Struct ockam_node::Cancel
source · pub struct Cancel<'ctx, M: Message> { /* private fields */ }
Expand description
A message wrapper type that allows users to cancel message receival
A worker can block in place to wait for a message. If the next message is not the desired type, it can be cancelled which re-queues it into the mailbox.
Implementations§
source§impl<'ctx, M: Message> Cancel<'ctx, M>
impl<'ctx, M: Message> Cancel<'ctx, M>
sourcepub async fn cancel(self) -> Result<()>
pub async fn cancel(self) -> Result<()>
Cancel this message
This results in the message being re-queued at the back of the worker’s mailbox so that it can be handled by a future handle_message call
use ockam_node::Context;
use ockam_core::Result;
let msg = ctx.receive::<String>().await?;
if &*msg != "hello ockam" {
msg.cancel().await?;
}