pub struct ActorOwn<A: 'static> { /* private fields */ }
Expand description
An owning ref-counting reference to an actor
This not only keeps a reference to the actor, but it will also
automatically terminate the actor when the last owning reference
is dropped. This dereferences to a normal Actor
reference, so
when .clone()
is called on it, a normal non-owning reference
results. To get another owning reference, use .owned()
.
Implementations§
source§impl<A: 'static> ActorOwn<A>
impl<A: 'static> ActorOwn<A>
sourcepub fn new(
core: &mut Core,
notify: Ret<StopCause>,
parent_id: LogID
) -> ActorOwn<A>
pub fn new( core: &mut Core, notify: Ret<StopCause>, parent_id: LogID ) -> ActorOwn<A>
Create a new uninitialised actor of the given type. This is
in the Prep state. The reference can be cloned and passed
around and used to create Fwd
or Ret
instances.
However all calls to the actor will be delayed until the actor
moves into the Ready state.
notify
is the StopCause
return, which is called when the
actor terminates. parent_id
is the logging-ID of the parent
actor if known, or else 0.
See macros actor!
and actor_new!
for help with
creating and initialising actors.
sourcepub fn owned(&self) -> ActorOwn<A>
pub fn owned(&self) -> ActorOwn<A>
Create an additional owning reference to this actor. When the last owning reference is dropped, the actor is terminated, even when there are other references active.
sourcepub fn kill(&self, s: &mut Stakker, err: Box<dyn Error>)
pub fn kill(&self, s: &mut Stakker, err: Box<dyn Error>)
Kill actor, moving to Zombie state and dropping the
contained actor Self
value. The actor can never return from
the Zombie state. The provided error is used to generate
an StopCause::Killed
instance, which is passed to the
StopCause
handler set up when the actor was created.
sourcepub fn kill_str(&self, s: &mut Stakker, err: &'static str)
pub fn kill_str(&self, s: &mut Stakker, err: &'static str)
Kill actor, moving to Zombie state and dropping the
contained actor Self
value. The actor can never return from
the Zombie state. The provided error string is used to
generate an StopCause::Killed
instance, which is passed to
the StopCause
handler set up when the actor was created.
sourcepub fn kill_string(&self, s: &mut Stakker, err: impl Into<String>)
pub fn kill_string(&self, s: &mut Stakker, err: impl Into<String>)
Kill actor, moving to Zombie state and dropping the
contained actor Self
value. The actor can never return from
the Zombie state. The provided error string is used to
generate an StopCause::Killed
instance, which is passed to
the StopCause
handler set up when the actor was created.
sourcepub fn anon(self) -> ActorOwnAnon
pub fn anon(self) -> ActorOwnAnon
Convert into an anonymous owning reference. See
ActorOwnAnon
.
Examples found in repository?
33 34 35 36 37 38 39 40 41 42 43 44
fn main() {
let mut stakker = Stakker::new(Instant::now());
let s = &mut stakker;
let cat = actor!(s, Cat::init(), ret_nop!());
call_and_drop(fwd_to!([cat], sound() as ()), cat.anon());
let dog = actor!(s, Dog::init(), ret_nop!());
call_and_drop(fwd_to!([dog], sound() as ()), dog.anon());
s.run(Instant::now(), false);
}
Methods from Deref<Target = Actor<A>>§
sourcepub fn is_zombie(&self) -> bool
pub fn is_zombie(&self) -> bool
Check whether the actor is a zombie. Note that this call is
less useful than it appears, since the actor may become a
zombie between the time you make this call and whatever
asynchronous operation follows. It is better to make a call
with a ret_to!
callback which will send back a None
if
the actor has died or if the actor drops the Ret
for any
other reason.
sourcepub fn apply_prep(
&self,
s: &mut Stakker,
f: impl FnOnce(&mut Cx<'_, A>) -> Option<A>
)
pub fn apply_prep( &self, s: &mut Stakker, f: impl FnOnce(&mut Cx<'_, A>) -> Option<A> )
Apply a closure to the actor if it is in the Prep state, otherwise do nothing. This is used to implement deferred prep calls.
sourcepub fn apply(
&self,
s: &mut Stakker,
f: impl FnOnce(&mut A, &mut Cx<'_, A>) + 'static
)
pub fn apply( &self, s: &mut Stakker, f: impl FnOnce(&mut A, &mut Cx<'_, A>) + 'static )
Apply a closure to the actor when it reaches the Ready state. If the actor is already in the Ready state, the closure is executed immediately. If the actor is in the Prep state, then it queues the operation instead of executing it. This is used to implement deferred ready calls.
sourcepub fn query<R>(
&self,
s: &mut Stakker,
f: impl FnOnce(&mut A, &mut Cx<'_, A>) -> R
) -> Option<R>
pub fn query<R>( &self, s: &mut Stakker, f: impl FnOnce(&mut A, &mut Cx<'_, A>) -> R ) -> Option<R>
Query an actor from outside the runtime. This is a
synchronous call intended for use when interfacing to external
code. Executes the closure on the actor immediately if the
actor has a Self
value (i.e. is in the Ready state), and
returns the result. Otherwise returns None
.
sourcepub fn id(&self) -> LogID
pub fn id(&self) -> LogID
Get the logging-ID of this actor. If the logger feature isn’t enabled, returns 0.
sourcepub fn access_deferrer(&self) -> &Deferrer
pub fn access_deferrer(&self) -> &Deferrer
Used in macros to get a Deferrer
reference
sourcepub fn access_actor(&self) -> &Self
pub fn access_actor(&self) -> &Self
Used in macros to get an Actor
reference
sourcepub fn access_log_id(&self) -> LogID
pub fn access_log_id(&self) -> LogID
Used in macros to get the actor’s logging-ID. If the logger feature isn’t enabled, returns 0.