Skip to main content

tokio_actors/
lib.rs

1#![warn(missing_docs)]
2//! Tokio Actors is a light-weight, Tokio-native actor framework for building
3//! hierarchical systems with strongly-typed mailboxes, timers, and supervision.
4//!
5//! # Overview
6//! - Thread-safe actors that run as exclusive tasks on Tokio's multi-threaded runtime.
7//! - Typed request/response semantics through [`ActorHandle::send`](crate::actor::handle::ActorHandle::send).
8//! - Recurring timers, supervision hooks, and bounded mailboxes out of the box.
9//!
10//! ```rust,no_run
11//! use tokio_actors::{actor::{Actor, ActorExt, context::ActorContext}, ActorResult, StopReason};
12//!
13//! #[derive(Default)]
14//! struct Counter(i64);
15//!
16//! impl Actor for Counter {
17//!     type Message = i64;
18//!     type Response = i64;
19//!
20//!     async fn handle(&mut self, msg: i64, _ctx: &mut ActorContext<Self>) -> ActorResult<i64> {
21//!         self.0 += msg;
22//!         Ok(self.0)
23//!     }
24//! }
25//!
26//! #[tokio::main]
27//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
28//!     let counter = Counter::default().spawn().named("counter").await?;
29//!     counter.notify(5).await?;          // fire-and-forget
30//!     let total = counter.send(3).await?; // request-response -> 8
31//!     counter.stop(StopReason::Graceful).await?;
32//!     Ok(())
33//! }
34//! ```
35
36pub mod actor;
37pub mod error;
38pub mod system;
39pub mod types;
40
41pub use actor::{
42    context::{ActorContext, ChildSpawnBuilder, RecurringScheduleBuilder, ScheduleBuilder},
43    handle::ActorHandle,
44    runtime::{ActorConfig, MailboxConfig},
45    supervision::SupervisionConfig,
46    Actor, ActorExt, SpawnBuilder,
47};
48pub use error::{
49    ActorError, ActorResult, AskError, SendError, SpawnError, StreamError, SupervisionError,
50    TimerError, TrySendError,
51};
52pub use system::{ActorSystem, ShutdownPolicy, SystemConfig};
53pub use types::{
54    ActorId, ActorStatusInfo, ChildEvent, ChildInfo, MissPolicy, RecurringId, RestartStrategy,
55    RestartType, SchedulePolicy, Shutdown, StopReason, StreamEvent, StreamId, SupervisionAction,
56};