Skip to main content

Crate mesh_worker

Crate mesh_worker 

Source
Expand description

Infrastructure for workers, which are agents that mostly communicate via mesh message passing. These provide a way for splitting up your program into separable components, each of which can optionally run in a separate process.

§Overview

A worker is a self-contained component that:

  1. Is created from Parameters (Worker::new)
  2. Runs a main loop consuming WorkerRpc messages (Worker::run)
  3. Can be saved and restarted from State (Worker::restart)

Workers are registered at compile time with register_workers! and launched at runtime through a WorkerHost. The host can run workers in-process (on a new thread) or in a child process via mesh_process.

§Entry points

  • Worker trait — define a worker’s parameters, state, and behavior.
  • worker_host() — create a (WorkerHost, WorkerHostRunner) pair.
  • register_workers! — register worker types for dynamic lookup by name.
  • RegisteredWorkers — factory that resolves worker names to builders, using the compile-time registry.
  • WorkerHandle — handle to a running worker, supporting stop, restart, inspect, and lifetime events.

Macros§

register_workers
Registers workers for use with RegisteredWorkers.
runnable_workers
Generates a type that defines the set of workers that can be run by a worker host. Generate a type to that can be used to match a requested worker name and run it.

Structs§

RegisteredWorkers
A worker factory that can build any worker built with register_workers.
WorkerBuilder
A builder for a worker.
WorkerHandle
Represents a running Worker instance providing the ability to restart, stop or wait for exit. To launch a worker and get a handle, use WorkerHost::launch_worker
WorkerHost
A handle used to launch workers on a host.
WorkerHostRunner
A runner returned by worker_host(). Used to handle worker launch requests.
WorkerId
A unique identifier for a worker, used to specify which worker to launch.

Enums§

WorkerEvent
A lifetime event for a worker.
WorkerRpc
Common requests for workers.

Traits§

Worker
Trait implemented by workers.
WorkerFactory
Trait implemented by a type that can dispatch requests to a worker.

Functions§

launch_local_worker
Launches a worker locally.
worker_host
Returns a new WorkerHost, WorkerHostRunner pair.