Trait mesh_worker::Worker

source ·
pub trait Worker: 'static + Sized {
    type Parameters: 'static + Send;
    type State: MeshPayload;

    const ID: WorkerId<Self::Parameters>;

    // Required methods
    fn new(parameters: Self::Parameters) -> Result<Self>;
    fn restart(state: Self::State) -> Result<Self>;
    fn run(self, recv: Receiver<WorkerRpc<Self::State>>) -> Result<()>;
}
Expand description

Trait implemented by workers.

Required Associated Types§

source

type Parameters: 'static + Send

Parameters passed to launch the worker. Used with Worker::new.

For this worker to be spawned on a remote node, Parameters must implement MeshPayload.

source

type State: MeshPayload

State used to implement hot restart. Used with Worker::restart.

Required Associated Constants§

source

const ID: WorkerId<Self::Parameters>

String identifying the Worker. Used when launching workers in separate processes to specify which workers are supported and which worker to launch. IDs must be unique within a given worker host.

Required Methods§

source

fn new(parameters: Self::Parameters) -> Result<Self>

Instantiates the worker.

The worker should not start running yet, but it can allocate any resources necessary to run.

source

fn restart(state: Self::State) -> Result<Self>

Restarts a worker from a previous worker’s execution state.

source

fn run(self, recv: Receiver<WorkerRpc<Self::State>>) -> Result<()>

Synchronously runs the worker on the current thread.

The worker should respond to commands sent in recv. If recv is closed, the worker should exit.

The worker ends when it returns from this function.

Object Safety§

This trait is not object safe.

Implementors§