pub struct FnWorker { /* private fields */ }Expand description
A Supervisable worker built from a plain future.
This is the ordinary kind of supervised child: a piece of asynchronous work that runs until it reaches its own terminal condition – an input channel closing, a loop finishing, a request completing.
§Shutdown
A worker created with new never gets a shutdown signal, and it reports this through
wants_shutdown_signal. Shutdown of a subtree is a trigger, not an
enforcement: the workers within it keep running until their terminal conditions are reached, which is what lets a
set of tasks connected by channels drain in dependency order without any of them having to know that order. The
worker’s shutdown timeout (five seconds by default) is the backstop for work that takes too long, and
ShutdownStrategy::Brutal is the answer for work that has no terminal condition at all.
Some workers must observe shutdown, for example a worker that:
- must stop a long-lived connection gracefully
- must run cleanup
- has no other way to know when to stop
Create such a worker with with_shutdown instead, which gives its body the signal.
This worker cannot be restarted, as the future is consumed during initialization. It reports this through
can_restart, so its owner never restarts it.
Implementations§
Source§impl FnWorker
impl FnWorker
Sourcepub fn new<N, Fut>(name: N, fut: Fut) -> Self
pub fn new<N, Fut>(name: N, fut: Fut) -> Self
Creates a worker that runs fut to completion.
Workers may return either () or Result<(), GenericError>.
Prefer worker and its counterparts on
SupervisorHandle, which wrap this up with the defaults appropriate to a
dynamically spawned child.
§Examples
let worker = FnWorker::new("queue_drainer", drain_queue());Sourcepub fn with_shutdown<N, F, Fut>(name: N, f: F) -> Self
pub fn with_shutdown<N, F, Fut>(name: N, f: F) -> Self
Creates a worker whose body gets the shutdown signal.
f is called once, when the worker starts. Its argument is the [ShutdownHandle] that the owner of the worker
fires when the worker must stop.
Prefer worker_with_shutdown and its counterpart on
SupervisorHandle. These functions wrap this function with the correct
defaults for a dynamically spawned child.
§Examples
let worker = FnWorker::with_shutdown("conn_handler", |shutdown| serve_until(shutdown));Trait Implementations§
Source§impl Supervisable for FnWorker
impl Supervisable for FnWorker
Source§fn shutdown_strategy(&self) -> ShutdownStrategy
fn shutdown_strategy(&self) -> ShutdownStrategy
Source§fn wants_shutdown_signal(&self) -> bool
fn wants_shutdown_signal(&self) -> bool
Source§fn can_restart(&self) -> bool
fn can_restart(&self) -> bool
Source§fn initialize<'life0, 'async_trait>(
&'life0 self,
process_shutdown: ShutdownHandle,
) -> Pin<Box<dyn Future<Output = Result<SupervisorFuture, InitializationError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn initialize<'life0, 'async_trait>(
&'life0 self,
process_shutdown: ShutdownHandle,
) -> Pin<Box<dyn Future<Output = Result<SupervisorFuture, InitializationError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Auto Trait Implementations§
impl !Freeze for FnWorker
impl RefUnwindSafe for FnWorker
impl Send for FnWorker
impl Sync for FnWorker
impl Unpin for FnWorker
impl UnsafeUnpin for FnWorker
impl UnwindSafe for FnWorker
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Track for T
impl<T> Track for T
§fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self>
fn track_resources(self, token: ResourceGroupToken) -> Tracked<Self>
Tracked wrapper. Read more§fn in_current_resource_group(self) -> Tracked<Self>
fn in_current_resource_group(self) -> Tracked<Self>
Tracked wrapper. Read more