You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ector is an open source async, no-alloc actor framework for embedded devices
Ector is an open source async, no-alloc actor framework for embedded devices. It integrates with embassy, the embedded async project.
Actor System
An actor system is a framework that allows for isolating state within narrow contexts, making it easier to reason about system.
Within a actor system, the primary component is an Actor, which represents the boundary of state usage.
Each actor has exclusive access to its own state and only communicates with other actors through message-passing.
Example
use ector::*;/// A Counter that we wish to create an Actor for.pubstructCounter{count:u32,}// The message our actor will handle.pubstructIncrement;/// An Actor implements the Actor trait.implActorforCounter{/// The Message associated type is the message types that the Actor can receive.typeMessage = Increment;/// An actor has to implement the on_mount method. on_mount() is invoked when the internals of an actor is ready,/// and the actor can begin to receive messages from an inbox.////// The following arguments are provided:/// * The address to 'self'/// * An inbox from which the actor can receive messagesasyncfnon_mount<M>(&mutself, _:DynamicAddress<Self::Message>,mutinbox:M) -> !
whereM:Inbox<Self::Message>{loop{// Await the next message and increment the counterlet _ = inbox.next().await;self.count += 1;}}}/// The entry point of the application is using the embassy runtime.#[embassy_executor::main]asyncfnmain(spawner: embassy_executor::Spawner){// Mounting the Actor will spawn an embassy tasklet addr = ector::actor!(spawner, counter,Counter,Counter{ count:0});// The actor address may be used in any embassy task to communicate with the actor.let _ = addr.notify(Increment).await;}
Building
You can build and test the framework by running
cargo test
Directory layout
ector - an actor framework
macros - macros used by application code to simplify