Skip to main content

BackgroundService

Trait BackgroundService 

Source
pub trait BackgroundService: Send {
    // Required methods
    fn name(&self) -> &str;
    fn run(
        self: Box<Self>,
        state: Arc<StateMap>,
        shutdown: Shutdown,
    ) -> BoxFuture<()>;
}
Expand description

Long-running work started after on_startup, stopped after connection drain.

Services are process-local — they are not shared across processes. Prefer one service per concern (UDP socket, queue worker, …).

Required Methods§

Source

fn name(&self) -> &str

Source

fn run( self: Box<Self>, state: Arc<StateMap>, shutdown: Shutdown, ) -> BoxFuture<()>

Run until shutdown becomes true (or the future completes).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§