Address API

Send messages to actors and check their status.

Addr<A>

The Addr type is a handle to send messages to an actor. It's cheap to clone and can be passed between actors.

1
2
3

Addr implements Clone, so you can freely share addresses between actors.

Request-Response

pub async fn send<M>(&self, msg: M) -> Result<M::Result, MailboxError>

Send a message and wait for the response. Blocks until the handler returns.

Returns: Result<M::Result, MailboxError>

Where: A: Handler<M>, M: Message

pub async fn send_timeout<M>(&self, msg: M, timeout: Duration) -> Result<M::Result, MailboxError>

Send a message with a timeout. Returns MailboxError::Timeout if no response within the duration.

Returns: Result<M::Result, MailboxError>

Where: A: Handler<M>, M: Message

pub async fn send_async<M>(&self, msg: M) -> Result<M::Result, MailboxError>

Send to an AsyncHandler and wait for response.

Returns: Result<M::Result, MailboxError>

Where: A: AsyncHandler<M>, M: Message

Fire-and-Forget

pub async fn do_send<M>(&self, msg: M) -> Result<(), MailboxError>

Send a message without waiting for a response. Waits for mailbox space if full.

Returns: Result<(), MailboxError>

Where: A: Handler<M>, M: Message

pub async fn do_send_async<M>(&self, msg: M) -> Result<(), MailboxError>

Fire-and-forget for AsyncHandler.

Returns: Result<(), MailboxError>

Where: A: AsyncHandler<M>, M: Message

pub fn try_send<M>(&self, msg: M) -> Result<(), MailboxError>

Non-blocking send. Returns immediately with MailboxFull if mailbox is at capacity.

Returns: Result<(), MailboxError>

Where: A: Handler<M>, M: Message

pub fn try_send_async<M>(&self, msg: M) -> Result<(), MailboxError>

Non-blocking send for AsyncHandler.

Returns: Result<(), MailboxError>

Where: A: AsyncHandler<M>, M: Message

Status

pub fn id(&self) -> ActorId

Get the actor's unique identifier.

Returns: ActorId

pub fn is_alive(&self) -> bool

Check if the actor is still running. Returns false if the actor has stopped.

Returns: bool

Method Comparison

MethodWaits for ResponseBlockingUse Case
sendYesAsync awaitQuery data, request-response
send_timeoutYes (with limit)Async awaitRequests with deadlines
do_sendNoAsync (mailbox)Commands, notifications
try_sendNoNeverBroadcasting, non-critical

Usage Examples

Query Pattern

1
2
3
4
5
6
7
8
9
10

Command Pattern

1
2
3
4
5
6
7
8

Broadcast Pattern

1
2
3
4
5
6
7
8
9
10
11
12

Health Check

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

Related