Lakka
Description
Actor system inspired by Alice Ryhls Actors with Tokio blog post, improved with macros to reduce boilerplate and create a more friendlier user experience. The functionality of this library is focused on the actor message ergonomics, and there are no built in actor supervision, support for distributed actors or other more sophisticated features.
Installation
# TODO: the library is not in the registry yet
Usage
Adding #[messages] macro to an impl block will make all the functions with &self and &mut self callable from an actor handle. Calling run() returns an actor handle, that can be cloned and passed around.
use Duration;
use *;
//Only macro needed to use lakka. Will generate CounterHandle, necessary enums for messages and implement Actor trait etc.
async
Features
#[messages]macro for bounded Actor, this is the typical usage. Usestokio::sync::mpsc::channelto deliver messages to the actor..run()defaults to channel size 100. Withrun_boundedthe channel size can be customized.#[messages(unbounded)]for "unbounded" actor, when unbounded channel for messages is needed. Usestokio::sync::mpsc::unbounded_channel. The main difference that sending of the messages are not awaited. This can be useful f.e. when Actor implementsDrop(non async) and needs to signal another actor through it's handle.- Actor can receive messages from multiple sources naturally when an actor handle is cloned, but in addition to this the actor can have additional ActorTellChannels to receive messages from, that can be registered either with
run_with_channelsfunction, or in#[messages]block function by calling_ctx.extra_rxs.push(receiver). This can be useful with broadcast type scenario, like chats.
Check the examples for more examples!
Behind the scenes
The #[messages] macro in the above example generates code to implement lakka::Actor for Counter, struct CounterHandle, an enum CounterAskMessage with an enum variant for each function that returns a value, and an enum CounterTellMessage with a variant for each function that doesn't return a value.
//Generated code:
pub use *;
Contributing
Contributions are always welcome!
License
This project is licensed under either of:
- MIT License
- Apache License, Version 2.0
at your option.