Skip to main content

System

Struct System 

Source
pub struct System { /* private fields */ }
Expand description

Systems are responsible for keeping track of their spawned actors, and managing their lifecycles appropriately.

You may run multiple systems in the same application, each system being responsible for its own pool of actors.

Implementations§

Source§

impl System

Source

pub fn prepare_async<A>( &mut self, actor: A, ) -> AsyncSpawnBuilderWithoutAddress<'_, A, Ready<A>>
where A: AsyncActor,

Prepare an async actor to be spawned. Returns an AsyncSpawnBuilderWithoutAddress which has to be further configured before spawning the actor.

Source

pub fn prepare_async_factory<A, F>( &mut self, factory: F, ) -> AsyncSpawnBuilderWithoutAddress<'_, A, F>
where A: AsyncActor, F: IntoFuture<Output = A>,

Similar to Self::prepare_async(), but an async actor factory is passed instead of an AsyncActor itself. This is used when an actor needs to be created on its own thread instead of the calling thread. Returns an AsyncSpawnBuilderWithoutAddress which has to be further configured before spawning the actor.

Source

pub fn spawn_async<A>( &mut self, actor: A, ) -> Result<Addr<A::Message>, ActorError>
where A: AsyncActor + Send + 'static,

Spawn an AsyncActor in the system, returning its address when successful. This address is created by the system and uses a default capacity. If you need to customize the address see Self::prepare_async() or Self::prepare_async_factory().

Source§

impl System

Source

pub fn new(name: &str) -> Self

Creates a new System with a given name.

Source

pub fn with_callbacks(name: &str, callbacks: SystemCallbacks) -> Self

Source

pub fn prepare<A>( &mut self, actor: A, ) -> SpawnBuilderWithoutAddress<'_, A, impl FnOnce() -> A + use<A>>
where A: Actor,

Prepare an actor to be spawned. Returns a SpawnBuilderWithoutAddress which has to be further configured before spawning the actor.

Source

pub fn prepare_fn<A, F>( &mut self, factory: F, ) -> SpawnBuilderWithoutAddress<'_, A, F>
where A: Actor, F: FnOnce() -> A + Send,

Similar to Self::prepare(), but an actor factory is passed instead of an Actor itself. This is used when an actor needs to be created on its own thread instead of the calling thread. Returns a SpawnBuilderWithoutAddress which has to be further configured before spawning the actor.

Source

pub fn spawn<A>(&mut self, actor: A) -> Result<Addr<A::Message>, ActorError>
where A: Actor<Context = Context<<A as Actor>::Message>> + Send + 'static,

Spawn a normal Actor in the system, returning its address when successful. This address is created by the system and uses a default capacity. If you need to customize the address see Self::prepare() or Self::prepare_fn().

Source

pub fn run(&mut self) -> Result<(), ActorError>

Block the current thread until the system is shutdown.

Methods from Deref<Target = SystemHandle>§

Source

pub fn shutdown(&self) -> Result<(), ActorError>

Stops all actors spawned by this system.

Source

pub fn subscribe_recipient<M: 'static, E: Event + Into<M>>( &self, recipient: Recipient<M>, )

Subscribe given recipient to events of type E. See BareContext::subscribe().

Source

pub fn subscribe_and_receive_latest<M: 'static, E: Event + Into<M>>( &self, recipient: Recipient<M>, ) -> Result<(), SendError>

Subscribe given recipient to events of type E and send the last cached event to it. See BareContext::subscribe_and_receive_latest().

Source

pub fn publish<E: Event>(&self, event: E) -> Result<(), PublishError>

Publish an event. All actors that have previously subscribed to the type will receive it.

The event will be also cached. Actors that will subscribe to the type in future may choose to receive the last cached event upon subscription.

When sending to some subscriber fails, others are still tried and vec of errors is returned. For direct, non-Clone or high-throughput messages please use Addr or Recipient.

Source

pub fn name(&self) -> &str

Source

pub fn is_running(&self) -> bool

Return true if the actor system is running (not shutting down, not stopped).

Trait Implementations§

Source§

impl Default for System

Source§

fn default() -> System

Returns the “default value” for a type. Read more
Source§

impl Deref for System

Source§

type Target = SystemHandle

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Drop for System

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for System

§

impl !RefUnwindSafe for System

§

impl Send for System

§

impl Sync for System

§

impl Unpin for System

§

impl !UnwindSafe for System

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.