Struct heph::actor_ref::ActorRef [−][src]
pub struct ActorRef<M> { /* fields omitted */ }
Expand description
Actor reference.
An actor reference reference can be used to send messages to an actor, for more details see the module documentation.
Implementations
Send a message to the actor.
See Sending messages and ActorRef::try_send
for more details.
Notes
Mapped actor references, see ActorRef::map
and
ActorRef::try_map
, require an allocation and might be expensive. If
possible try ActorRef::try_send
first, which does not require an
allocation. Regular (i.e. non-mapped) actor references do not require an
allocation.
Attempt to send a message to the actor.
Some types of actor references can detect errors in sending a message,
however not all actor references can. This means that even if this
methods returns Ok
it does not mean that the message is guaranteed
to be delivered to or handled by the actor.
See Sending messages for more details.
Change the message type of the actor reference.
Before sending the message this will first change the message into a
different type. This is useful when you need to send to different types
of actors (using different message types) from a central location. For
example in process signal handling, see RuntimeRef::receive_signals
.
Notes
This conversion is not cheap, it requires an allocation so use with caution when it comes to performance sensitive code.
Prefer to clone an existing mapped ActorRef
over creating a new one as
that can reuse the allocation mentioned above.
Much like map
, but uses the TryFrom
trait.
This creates a new actor reference that attempts to map from one message type to another before sending. This is useful when you need to send to different types of actors from a central location.
Notes
Errors converting from one message type to another are turned into
SendError
s.
This conversion is not cheap, it requires an allocation so use with caution when it comes to performance sensitive code.
Prefer to clone an existing mapped ActorRef
over creating a new one as
that can reuse the allocation mentioned above.
Returns a Future
that waits until the actor finishes running. Acts
similar to a JoinHandle
of a thread.
Returns true
if the actor to which this reference sends to is still
connected.
Notes
Even if this returns true
it doesn’t mean ActorRef::try_send
will
succeeded (even if the inbox isn’t full). There is always a race
condition between using this method and doing something based on it.
This does provide one useful feature: once this returns false
it will
never return true
again. This makes it useful in the use case where
creating a message is expansive, which is wasted if the actor is no
longer running. Thus this should only be used as optimisation to not do
work.
Trait Implementations
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Performs the conversion.
Creates a value from an iterator. Read more
Auto Trait Implementations
impl<M> !RefUnwindSafe for ActorRef<M>
impl<M> !UnwindSafe for ActorRef<M>
Blanket Implementations
Mutably borrows from an owned value. Read more