interruptible_worker

Function interruptible_worker 

Source
pub fn interruptible_worker<N, Fut>(name: N, fut: Fut) -> FnWorker
where N: Into<String>, Fut: Future + Send + 'static, Fut::Output: IntoWorkerResult,
Expand description

Creates a one-shot Supervisable worker that runs fut until it completes or shutdown is signalled, whichever happens first.

The future that is given is subsequently wrapped such that shutdown is always handled: the underlying worker cannot ignore or defer honoring it. The future is dropped at whatever await point it happens to be parked on when shutdown fires, so use this only for work that is safe to interrupt: a server accept loop, a background refresher, a connection handler. Anything that must finish what it started should use noninterruptible_worker and observe the shutdown signal itself.

Workers may return either () or Result<(), GenericError>.

The worker cannot be restarted as the given future is consumed during initialization.

ยงExamples

let worker = interruptible_worker("acceptor", run_accept_loop());