Skip to main content

Daemon

Trait Daemon 

Source
pub trait Daemon: Send + Sync {
    // Provided method
    fn run(
        &self,
        app: &App,
        shutdown: CancellationToken,
    ) -> impl Future<Output = Result<(), StdError>> + Send { ... }
}
Expand description

A long-running background task managed by the application.

Daemons are started together by RunDaemonsExt::run_daemons and run until the shared CancellationToken is cancelled (for example on shutdown) or until any one of them returns, at which point the rest are signalled to stop. Each daemon is given its own child cancellation token.

The default run implementation does nothing and just waits for cancellation, which is handy for a daemon that only needs to keep a component alive.

Register a daemon with AddDaemonExt::add_daemon (a concrete instance) or AddDaemonServiceExt::add_daemon_service (resolved from a Service).

Provided Methods§

Source

fn run( &self, app: &App, shutdown: CancellationToken, ) -> impl Future<Output = Result<(), StdError>> + Send

Runs the daemon until shutdown is cancelled.

Implementations should return promptly once the token is cancelled. Returning Err causes RunDaemonsExt::run_daemons to stop the other daemons and surface the error.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§