Skip to main content

Worker

Trait Worker 

Source
pub trait Worker<N: Node>:
    Any
    + Send
    + Sync
    + Sized {
    type Config;
    type Error: Error;

    // Required method
    fn start<'life0, 'async_trait>(
        node: &'life0 mut N,
        config: Self::Config,
    ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn dependencies() -> &'static [TypeId] { ... }
    fn stop<'life0, 'async_trait>(
        self,
        _node: &'life0 mut N,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

A trait representing a node worker.

Node workers are conceptually similar to actors in the actor programming model, but differ slightly in a number of crucial ways.

  • Workers may register and access shared state, known as ‘resources’.
  • Workers have a topological ordering that determine when they should be started and stopped.

Required Associated Types§

Source

type Config

The configuration state required to start this worker.

Source

type Error: Error

An error that may be emitted during node startup and shutdown.

Required Methods§

Source

fn start<'life0, 'async_trait>( node: &'life0 mut N, config: Self::Config, ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Attempt to instantiate this worker with the given node and worker configuration.

Provided Methods§

Source

fn dependencies() -> &'static [TypeId]

Generate a list of TypeIds representing the topological worker dependencies of this worker.

Workers listed will be started before this worker and shut down after this worker.

Source

fn stop<'life0, 'async_trait>( self, _node: &'life0 mut N, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Attempt to stop an instance of this worker.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§