Struct thespis_impl::ActorBuilder
source · [−]pub struct ActorBuilder<A: Actor> { /* private fields */ }
Expand description
Implementations
sourceimpl<A: Actor> ActorBuilder<A>
impl<A: Actor> ActorBuilder<A>
sourcepub fn name(self, name: impl AsRef<str>) -> Self
pub fn name(self, name: impl AsRef<str>) -> Self
Configure a name for this actor. This will be helpful for interpreting
debug logs. You can also retrieve the name later on both the Addr
and the Mailbox
.
sourcepub fn bounded(self, bounded: Option<usize>) -> Self
pub fn bounded(self, bounded: Option<usize>) -> Self
Choose the bounded size of the default channel. If unset, will default to a bounded channel with a buffer size of 16. Note that thespis messages are boxed, so the buffer is only the size of 16 fat pointers. It still means consuming the actual heap storage if you count on the channel backpressure to keep your memory consumption down.
If you set this to None
, you will get an unbounded channel.
This option is incompatible with manually providing a channel. Only works for the default channel.
Panics
In debug mode this will panic if you have already called ActorBuilder::channel
.
sourcepub fn channel(self, tx: ChanSender<A>, rx: ChanReceiver<A>) -> Self
pub fn channel(self, tx: ChanSender<A>, rx: ChanReceiver<A>) -> Self
Set the channel to use for communication between Addr
and Mailbox
.
This option is incompatible with bounded.
Panics
In debug mode this will panic if you have already called ActorBuilder::bounded
.
sourcepub fn build(self) -> (Addr<A>, Mailbox<A>)
pub fn build(self) -> (Addr<A>, Mailbox<A>)
Build Addr
and Mailbox
. This does not yet consume an actor and you have to
call start
or start_local
on Mailbox
and spawn the future to
run your actor.
The advantage of this method is that you can pass the Addr to the constructor
of your actor if you need to. Otherwise it’s advised to use ActorBuilder::spawn_handle
or ActorBuilder::spawn_handle_local
for convenience.
sourcepub fn spawn(self, actor: A, exec: &dyn Spawn) -> Result<Addr<A>, ThesErr> where
A: Send,
pub fn spawn(self, actor: A, exec: &dyn Spawn) -> Result<Addr<A>, ThesErr> where
A: Send,
Spawn the mailbox on the provided executor. Returns Addr
. Note that this detaches the
mailbox on spawning. That means the actor will keep running until all Addr to it have been
dropped.
If you want more control over stopping the actor, look at ActorBuilder::spawn_handle
or
ActorBuilder::build
.
sourcepub fn spawn_handle(
self,
actor: A,
exec: &dyn SpawnHandle<MailboxEnd<A>>
) -> Result<(Addr<A>, JoinHandle<MailboxEnd<A>>), ThesErr> where
A: Send,
pub fn spawn_handle(
self,
actor: A,
exec: &dyn SpawnHandle<MailboxEnd<A>>
) -> Result<(Addr<A>, JoinHandle<MailboxEnd<A>>), ThesErr> where
A: Send,
Spawn the mailbox on the provided executor. Returns Addr
and a JoinHandle
to the spawned
mailbox.
Note that if you drop the JoinHandle
it will stop the actor and drop it unless
you call JoinHandle::detach
on it.
The JoinHandle
returns:
MailboxEnd::Mailbox
if you actor panicked whilst processing a message. This way you can instantiate a new actor and spawn the mailbox again. This can be used for supervision. All existing addresses will remain valid when this happens.MailboxEnd::Actor
when the mailbox ends naturally. You can create a new mailbox and spawn the actor again if you want to re-use it.
sourcepub fn spawn_local(
self,
actor: A,
exec: &dyn LocalSpawn
) -> Result<Addr<A>, ThesErr>
pub fn spawn_local(
self,
actor: A,
exec: &dyn LocalSpawn
) -> Result<Addr<A>, ThesErr>
For Actor: !Send
. Spawn the mailbox on the provided executor. Returns the Addr
.
If you want more control over stopping the actor, look at ActorBuilder::spawn_handle_local
or
ActorBuilder::build
.
sourcepub fn spawn_handle_local(
self,
actor: A,
exec: &dyn LocalSpawnHandle<MailboxEnd<A>>
) -> Result<(Addr<A>, JoinHandle<MailboxEnd<A>>), ThesErr>
pub fn spawn_handle_local(
self,
actor: A,
exec: &dyn LocalSpawnHandle<MailboxEnd<A>>
) -> Result<(Addr<A>, JoinHandle<MailboxEnd<A>>), ThesErr>
For Actor: !Send
. Spawn the mailbox on the provided executor. Returns Addr
and a JoinHandle
to the spawned
mailbox.
Note that if you drop the JoinHandle
it will stop the actor and drop it unless
you call JoinHandle::detach
on it.
Trait Implementations
sourceimpl<A: Actor> Debug for ActorBuilder<A>
impl<A: Actor> Debug for ActorBuilder<A>
Auto Trait Implementations
impl<A> !RefUnwindSafe for ActorBuilder<A>
impl<A> Send for ActorBuilder<A>
impl<A> !Sync for ActorBuilder<A>
impl<A> Unpin for ActorBuilder<A>
impl<A> !UnwindSafe for ActorBuilder<A>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
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
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more