pub trait Work {
// Required methods
fn unpark(&mut self, cx: ManagedConstPtr<SubContext>) -> bool;
fn park(&mut self) -> bool;
fn name(&self) -> &str;
}Expand description
A trait for worker.
Worker should be able to park itself or unparked by a function call.
When the worker is unparked, worker should get ready to handle messages
using the passed SubContext. See an example code below.
ⓘ
fn unpark(&mut self, cx: ManagedConstPtr<SubContext>) -> bool {
// Sends `cx` to the associated worker.
self.tx.send(cx).is_ok();
}
fn worker_function(&self) {
// Parking during idle.
while let Ok(cx) = rx.recv() {
// `SubContext` provides message handling function for you.
SubContext::execute(cx);
}
}Required Methods§
Sourcefn unpark(&mut self, cx: ManagedConstPtr<SubContext>) -> bool
fn unpark(&mut self, cx: ManagedConstPtr<SubContext>) -> bool
Wakes the associated worker then call SubContext::execute on the
worker, and then returns true if all is ok.