Skip to main content

mesh_worker/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Infrastructure for workers, which are agents that mostly communicate via
5//! mesh message passing. These provide a way for splitting up your program into
6//! separable components, each of which can optionally run in a separate
7//! process.
8//!
9//! # Overview
10//!
11//! A worker is a self-contained component that:
12//! 1. Is created from `Parameters` ([`Worker::new`])
13//! 2. Runs a main loop consuming `WorkerRpc` messages ([`Worker::run`])
14//! 3. Can be saved and restarted from `State` ([`Worker::restart`])
15//!
16//! Workers are registered at compile time with [`register_workers!`] and
17//! launched at runtime through a [`WorkerHost`]. The host can run workers
18//! in-process (on a new thread) or in a child process via `mesh_process`.
19//!
20//! # Entry points
21//!
22//! - [`Worker`] trait — define a worker's parameters, state, and behavior.
23//! - [`worker_host()`] — create a `(WorkerHost, WorkerHostRunner)` pair.
24//! - [`register_workers!`] — register worker types for dynamic lookup by name.
25//! - [`RegisteredWorkers`] — factory that resolves worker names to builders,
26//!   using the compile-time registry.
27//! - [`WorkerHandle`] — handle to a running worker, supporting stop, restart,
28//!   inspect, and lifetime events.
29
30mod worker;
31
32// TODO: flatten this module.
33pub use worker::*;