Skip to main content

Runnable

Trait Runnable 

Source
pub trait Runnable<S>:
    Send
    + Sync
    + 'static {
    // Required method
    fn run<'async_trait>(
        self: Arc<Self>,
        state: S,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait;
}
Expand description

Capability trait for providers that produce a long-running runtime task.

run() is the ONLY place in the lifecycle for long-running work (accept loops, listeners, periodic tickers). It must NOT appear in register() or Provider::boot().

Config-driven gating: if the provider is disabled at runtime (e.g. an enabled: false config flag, or a single-instance service whose pinned worker_id doesn’t match this worker), this method MUST short-circuit and return Ok(()) immediately instead of starting the long task. The provider stays registered for downstream capability lookups; it just doesn’t run on this process.

Required Methods§

Source

fn run<'async_trait>( self: Arc<Self>, state: S, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,

Run the long-lived provider task spawned by the bootstrap/supervisor layer.

NOTICE (convention): If this future returns Err, implementation should log contextual failure details itself (provider/task specific metadata).

Reason:

  • Runtime layer handles lifecycle/control-flow only.
  • Runtime cannot reliably attach provider-specific business context.
  • Non-critical runnable errors are not centrally logged to avoid duplicate/no-context error lines.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§