Struct elfo_core::Context [−][src]
Expand description
An actor execution context.
Implementations
Transforms the context to another one with the provided source.
Updates the actor’s status.
ctx.set_status(ActorStatus::ALARMING.with_details("something wrong"));
Closes the mailbox, that leads to returning None
from recv()
and
try_recv()
after handling all available messages in the mailbox.
Returns true
if the mailbox has just been closed.
Sends a message using the routing system.
Returns Err
if the message hasn’t reached any mailboxes.
Example
// Fire and forget.
let _ = ctx.send(SomethingHappened).await;
// Fire or fail.
ctx.send(SomethingHappened).await?;
// Fire or log.
if let Some(err) = ctx.send(SomethingHappened).await {
warn!("...", error = err);
}
Returns a request builder.
Example
// Request and wait for a response.
let response = ctx.request(SomeCommand).resolve().await?;
// Request and wait for all responses.
for result in ctx.request(SomeCommand).all().resolve().await {
// ...
}
Sends a message to the specified recipient.
Returns Err
if the message hasn’t reached any mailboxes.
Example
// Fire and forget.
let _ = ctx.send_to(addr, SomethingHappened).await;
// Fire or fail.
ctx.send_to(addr, SomethingHappened).await?;
// Fire or log.
if let Some(err) = ctx.send_to(addr, SomethingHappened).await {
warn!("...", error = err);
}
pub fn try_send_to<M: Message>(
&self,
recipient: Addr,
message: M
) -> Result<(), TrySendError<M>>
pub fn try_send_to<M: Message>(
&self,
recipient: Addr,
message: M
) -> Result<(), TrySendError<M>>
Tries to send a message to the specified recipient.
Returns Err
if the message hasn’t reached mailboxes or they are full.
Example
// Fire and forget.
let _ = ctx.send(SomethingHappened).await;
// Fire or fail.
ctx.send(SomethingHappened).await?;
// Fire or log.
if let Some(err) = ctx.send(SomethingHappened).await {
warn!("...", error = err);
}
Responds to the requester with the provided response.
The token can be used only once.
msg!(match envelope {
(SomeRequest, token) => {
ctx.respond(token, SomeResponse);
}
})
pub fn unpack_config<'c>(&self, config: &'c AnyConfig) -> &'c C where
C: for<'de> Deserialize<'de> + 'static,
pub fn unpack_config<'c>(&self, config: &'c AnyConfig) -> &'c C where
C: for<'de> Deserialize<'de> + 'static,
Used to get the typed config from ValidateConfig
.
msg!(match envelope {
(ValidateConfig { config, .. }, token) => {
let new_config = ctx.unpack_config(&config);
ctx.respond(token, Err("oops".into()));
}
})
Trait Implementations
Auto Trait Implementations
impl<C = (), K = Singleton, S = ()> !RefUnwindSafe for Context<C, K, S>
impl<C = (), K = Singleton, S = ()> !UnwindSafe for Context<C, K, S>
Blanket Implementations
Mutably borrows from an owned value. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more