pub struct WorkerContext { /* private fields */ }Expand description
Utility for managing a worker’s context
A worker context is created for each worker thread and is responsible for managing the worker’s state, task tracking, and event handling.
Tip: All fields are wrapped inside Arc so it should be cheap to clone
Implementations§
Source§impl WorkerContext
impl WorkerContext
Sourcepub fn start(&mut self) -> Result<(), WorkerError>
pub fn start(&mut self) -> Result<(), WorkerError>
Start running the worker
Sourcepub fn restart(&mut self) -> Result<(), WorkerError>
pub fn restart(&mut self) -> Result<(), WorkerError>
Restart running the worker
Sourcepub fn track<F: Future>(&self, task: F) -> Tracked<F> ⓘ
pub fn track<F: Future>(&self, task: F) -> Tracked<F> ⓘ
Start a task that is tracked by the worker
Sourcepub fn pause(&self) -> Result<(), WorkerError>
pub fn pause(&self) -> Result<(), WorkerError>
Pauses a worker, preventing any new jobs from being polled
Sourcepub fn resume(&self) -> Result<(), WorkerError>
pub fn resume(&self) -> Result<(), WorkerError>
Resume a worker that is paused
Sourcepub fn stop(&self) -> Result<(), WorkerError>
pub fn stop(&self) -> Result<(), WorkerError>
Calling this function triggers shutting down the worker while waiting for any tasks to complete
Sourcepub fn get_service(&self) -> &str
pub fn get_service(&self) -> &str
Get the type of service
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns whether the worker is running
Sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Returns whether the worker is pending
Sourcepub fn task_count(&self) -> usize
pub fn task_count(&self) -> usize
Returns the current futures in the worker domain
This include futures spawned via worker.track
Sourcepub fn has_pending_tasks(&self) -> bool
pub fn has_pending_tasks(&self) -> bool
Returns whether the worker has pending tasks
Sourcepub fn is_shutting_down(&self) -> bool
pub fn is_shutting_down(&self) -> bool
Is the shutdown token called
Sourcepub fn wrap_listener<F: Fn(&WorkerContext, &Event) + Send + Sync + 'static>(
&mut self,
f: F,
)
pub fn wrap_listener<F: Fn(&WorkerContext, &Event) + Send + Sync + 'static>( &mut self, f: F, )
Wraps the event listener with a new function
Trait Implementations§
Source§impl Clone for WorkerContext
impl Clone for WorkerContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WorkerContext
impl Debug for WorkerContext
Source§impl Drop for WorkerContext
impl Drop for WorkerContext
Source§impl<Args: Sync, Ctx: Sync, IdType: Sync + Send> FromRequest<Task<Args, Ctx, IdType>> for WorkerContext
impl<Args: Sync, Ctx: Sync, IdType: Sync + Send> FromRequest<Task<Args, Ctx, IdType>> for WorkerContext
Source§type Error = MissingDataError
type Error = MissingDataError
Source§impl Future for WorkerContext
impl Future for WorkerContext
Auto Trait Implementations§
impl Freeze for WorkerContext
impl !RefUnwindSafe for WorkerContext
impl Send for WorkerContext
impl Sync for WorkerContext
impl Unpin for WorkerContext
impl !UnwindSafe for WorkerContext
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn map<U, F>(self, f: F) -> Map<Self, F> ⓘ
fn map<U, F>(self, f: F) -> Map<Self, F> ⓘ
Source§fn map_into<U>(self) -> MapInto<Self, U>
fn map_into<U>(self) -> MapInto<Self, U>
Source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
f. Read moreSource§fn left_future<B>(self) -> Either<Self, B>
fn left_future<B>(self) -> Either<Self, B>
Source§fn right_future<A>(self) -> Either<A, Self>
fn right_future<A>(self) -> Either<A, Self>
Source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
Source§fn flatten(self) -> Flatten<Self>
fn flatten(self) -> Flatten<Self>
Source§fn flatten_stream(self) -> FlattenStream<Self>
fn flatten_stream(self) -> FlattenStream<Self>
Source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
poll will never again be called once it has
completed. This method can be used to turn any Future into a
FusedFuture. Read moreSource§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Source§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
Source§fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
Source§fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
Source§fn unit_error(self) -> UnitError<Self>where
Self: Sized,
fn unit_error(self) -> UnitError<Self>where
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = ()>.Source§fn never_error(self) -> NeverError<Self>where
Self: Sized,
fn never_error(self) -> NeverError<Self>where
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = Never>.