Expand description
§toktor
A small Actor framework for use within tokio.
Features:
- both graceful and hard shutdown options for actors
- spawn child actors
- spawn associated tasks, that may be shut down with the actor
This was created to cater for a need in a project for allowing creation of complex actor structures that could be easily shutdown when required. For example in UIs, when a user closes a window, or in telephony when a call is dropped.
§Example
use toktor::{Actor, ActorContext};
pub struct CountingActor {
total: usize,
}
impl Actor<usize> for CountingActor {
async fn on_message(&mut self, _ctx: &ActorContext, number: usize) {
self.total += number
}
}
let actor = toktor::spawn(16, CountingActor { total: 0 });
assert!(actor.send(1).await.is_ok());
Structs§
- Actor
Context - A context actor, that can be used by the actor to spawn associated tasks, child actors, or shut down the actor.
- Actor
Handle - A handle to an Actor, that can be used to send messages, or shut down the actor.
Enums§
- Actor
Error - An error returned from the
ActorContext::spawnorActorContext::spawn_childfunctions.
Traits§
- Actor
- Provides actor functions.
Functions§
- spawn
- Spawns an Actor, returning an
ActorHandlethat can be used to send messages, or shut down the actor.