speare
speare is a minimalistic actor framework. A thin abstraction over tokio tasks and flume channels with supervision inspired by Akka.NET. Read The Speare Book for more details on how to use the library.
Quick Look
A minimal Counter actor:
use *;
use Duration;
use time;
async
Props & Request-Response
Props, request-response via Request<Req, Res>, and the From trick for ergonomic sends:
use *;
use From;
async
PubSub & Registry
Type-safe publish/subscribe across actors, and a global registry for finding actors by type or name:
use *;
use From;
// PubSub messages must be Clone
;
// Logger subscribes to the "events" topic
;
// Greeter is registered so others can find it without holding a Handle
;
async
Supervision
Spawn supervised children with automatic restarts, backoff, and a watch callback for when retries are exhausted:
use *;
use Duration;
// inside a parent actor's init:
let worker = ctx.
.supervision
.watch
.spawn;
Why speare?
speare is a minimal abstraction layer over tokio green threads and flume channels, offering functionality to manage these threads, and pass messages between these in a more practical manner. The question instead should be: "why message passing (channels) instead of sharing state (e.g. Arc<Mutex<T>>)?"
- Easier reasoning: With message passing, each piece of data is owned by a single thread at a time, making the flow of data and control easier to reason about.
- Deadlock Prevention: Shared state with locks (like mutexes) can lead to deadlocks if not managed carefully. Message passing, especially in Rust, is less prone to deadlocks as it doesn’t involve traditional locking mechanisms.
- Encouragement of Decoupled Design: Message passing promotes a more modular, decoupled design where components communicate through well-defined interfaces (channels), enhancing maintainability and scalability of the code.
FAQ
How fast is speare?
I haven't benchmarked the newest versions yet, nor done any performance optimizations as well. There is an overhead due to boxing when sending messages, but overall it is pretty fast. Benchmarks TBD and added here in the future.
Is it production ready?
Not yet! But soon :-)
Why should I use this as opposed to the other 3 billion Rust actor frameworks?
I built speare because I wanted a very minimal actor framework providing just enough to abstract over tokio green threads and channels without introducing a lot of boilerplate or a lot of new concepts to my co-workers. You should use speare if you like its design, if not then don't :-)
Can I contribute?
Sure! There are only two rules to contribute:
- Be respectful
- Don't be an asshole
Keep in mind I want to keep this very minimalistic, but am very open to suggestions and new ideas :)