actor-helper-0.1.0 has been yanked.
actor-helper
A minimal, ergonomic actor runtime built on top of Tokio.
Features
- Simple API: Create actors with just a handle and receiver
- Type-safe: Compile-time guarantees for actor interactions
- Panic-safe: Automatic panic capture and error propagation
- Ergonomic macros:
act!andact_ok!for writing actor actions - Thread-safe: Clone handles to communicate from anywhere
Direct Actor Access
actor-helper provides direct mutable access to actor state through closures. Instead of defining message types and handlers, you write functions that directly manipulate the actor:
// Traditional message passing approach:
// actor.send(Increment(5)).await?;
// actor-helper approach - direct function execution:
handle.call.await?;
This design offers several advantages:
- No message types: Write functions directly instead of defining enums/structs
- Type safety: Full compile-time checking of actor interactions
- Flexibility: Execute any logic on the actor state, including async operations
- Simplicity: Less boilerplate, more readable code
The Handle is clonable and can be shared across threads, but all access to the actor's mutable state is serialized through the actor's mailbox, maintaining single-threaded safety.
⚠️ Important: Keep Actions Fast
Actions passed to handle.call() should complete quickly. The actor processes actions sequentially, so a slow action blocks the entire mailbox:
// ❌ DON'T: Long-running operations block the actor
handle.call.await?;
// ✅ DO: Spawn long-running work separately
handle.call.await?;
For background work or continuous tasks, implement them in the actor's run() method using tokio::select!.
Quick Start
Add to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["rt-multi-thread", "sync"] }
= "1"
Example
use ;
use ;
use mpsc;
// Public API
// Private actor implementation
async
License
MIT