Struct agner_actors::System
source · [−]pub struct System(_);Implementations
sourceimpl System
impl System
pub fn rc_downgrade(&self) -> SystemWeakRef
sourceimpl System
impl System
sourcepub fn new(config: SystemConfig) -> Self
pub fn new(config: SystemConfig) -> Self
Create a new System using the provided config.
sourcepub fn config(&self) -> &SystemConfig
pub fn config(&self) -> &SystemConfig
The config with which this System was created.
sourceimpl System
impl System
sourcepub async fn spawn<Behaviour, Args, Message>(
&self,
behaviour: Behaviour,
args: Args,
spawn_opts: SpawnOpts
) -> Result<ActorID, SysSpawnError>where
Args: Send + Sync + 'static,
Message: Unpin + Send + Sync + 'static,
for<'a> Behaviour: Actor<'a, Args, Message>,
pub async fn spawn<Behaviour, Args, Message>(
&self,
behaviour: Behaviour,
args: Args,
spawn_opts: SpawnOpts
) -> Result<ActorID, SysSpawnError>where
Args: Send + Sync + 'static,
Message: Unpin + Send + Sync + 'static,
for<'a> Behaviour: Actor<'a, Args, Message>,
Spawn an actor
Example:
use agner_actors::{System, Context, Event};
async fn actor_behaviour(context: &mut Context<&'static str>, actor_name: &'static str) {
loop {
if let Event::Message(message) = context.next_event().await {
eprintln!("[{}] received: {}", actor_name, message);
}
}
}
let _ = async {
let system = System::new(Default::default());
let alice = system.spawn(actor_behaviour, "Alice", Default::default()).await.expect("Failed to spawn an actor");
let bob = system.spawn(actor_behaviour, "Bob", Default::default()).await.expect("Failed to spawn an actor");
};sourcepub async fn exit(&self, actor_id: ActorID, exit_reason: Exit)
pub async fn exit(&self, actor_id: ActorID, exit_reason: Exit)
Send SigExit to the specified actor.
sourcepub fn wait(&self, actor_id: ActorID) -> impl Future<Output = Exit>
pub fn wait(&self, actor_id: ActorID) -> impl Future<Output = Exit>
Wait for the specified actor to terminate, and return upon its termination the
[ExitReason]. In case the actor with the specified actor_id does not exist — return
[ExitReason::NoProcess] right away.
sourcepub async fn send<M>(&self, to: ActorID, message: M)where
M: Send + Sync + 'static,
pub async fn send<M>(&self, to: ActorID, message: M)where
M: Send + Sync + 'static,
Send a single message to the specified actor.
sourcepub async fn channel<M>(
&self,
to: ActorID
) -> Result<UnboundedSender<M>, SysChannelError>where
M: Send + Sync + 'static,
pub async fn channel<M>(
&self,
to: ActorID
) -> Result<UnboundedSender<M>, SysChannelError>where
M: Send + Sync + 'static,
Open a channel to the specified actor.
sourcepub async fn add_data<D: Any + Send + Sync + 'static>(
&self,
actor_id: ActorID,
data: D
)
pub async fn add_data<D: Any + Send + Sync + 'static>(
&self,
actor_id: ActorID,
data: D
)
Associate arbitrary data with the specified actor. Upon actor termination that data will be dropped. If no actor with the specified id exists, the data will be dropped right away.
pub fn all_actors(&self) -> impl Stream<Item = ActorID> + '_
pub async fn actor_info(&self, actor_id: ActorID) -> Option<ActorInfo>
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for System
impl Send for System
impl Sync for System
impl Unpin for System
impl !UnwindSafe for System
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more