Struct tonari_actor::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 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) -> SpawnBuilder<'_, A, impl FnOnce() -> A>where A: Actor + 'static,

Prepare an actor to be spawned. Returns a SpawnBuilder which can be used to customize the spawning of the actor.

source

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

Similar to 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 SpawnBuilder which can be used to customize the spawning of the actor.

source

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

Spawn a normal Actor in the system, returning its address when successful.

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 Context::subscribe().

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.

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 is_running(&self) -> bool

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

§

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 !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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.