pub struct Worker<T> { /* private fields */ }Expand description
Server worker.
A worker runs one service instance on its own arbiter thread. It receives items through an unbounded channel. Clones refer to the same worker.
Implementations§
Source§impl<T> Worker<T>
impl<T> Worker<T>
Sourcepub fn start<F>(name: String, cfg: F, cpu: Option<usize>) -> Worker<T>where
T: Send + 'static,
F: ServerConfiguration<Item = T>,
pub fn start<F>(name: String, cfg: F, cpu: Option<usize>) -> Worker<T>where
T: Send + 'static,
F: ServerConfiguration<Item = T>,
Starts a worker on a new arbiter thread.
Returns immediately. The worker reports
Unavailable until its service is
created. If cpu is set, the worker thread is pinned to the logical
CPU with that index. On Windows, CPUs are numbered across processor
groups, the CPUs of group 1 follow the CPUs of group 0. Pinning is
supported on Windows, Linux and Android.
Sourcepub fn send(&self, msg: T) -> Result<(), T>
pub fn send(&self, msg: T) -> Result<(), T>
Sends a message to the worker.
Returns Ok if the message was queued. The message is queued even if
the worker is currently unavailable. Returns the message as Err if
the worker has stopped.
Sourcepub fn status(&self) -> WorkerStatus
pub fn status(&self) -> WorkerStatus
Returns the current worker status.
Sourcepub async fn wait_for_status(&mut self) -> WorkerStatus
pub async fn wait_for_status(&mut self) -> WorkerStatus
Waits for a status change not yet reported by this handle and returns the current status.
Each handle tracks the changes it has reported, so every clone observes every change. A clone starts with the reported changes of the handle it was cloned from. Several changes between calls are reported once. Returns immediately if the worker has failed.
Sourcepub fn stop(&self, timeout: Millis) -> WorkerStop ⓘ
pub fn stop(&self, timeout: Millis) -> WorkerStop ⓘ
Stops the worker.
The worker stops accepting items and shuts down its service, waiting
up to timeout. A zero timeout uses the default of 3 seconds.
Trait Implementations§
impl<T> Eq for Worker<T>
Source§impl<T> Ord for Worker<T>
impl<T> Ord for Worker<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Worker<T>
impl<T> !Unpin for Worker<T>
impl<T> !UnsafeUnpin for Worker<T>
impl<T> !UnwindSafe for Worker<T>
impl<T> Freeze for Worker<T>
impl<T> Send for Worker<T>
impl<T> Sync for Worker<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.