Address

The handle for communicating with actors.

What is an Address?

Addr<A> is a typed handle to an actor. It's how you send messages to actors from anywhere in your application:

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

Sending Messages

Three patterns for different use cases:

Request-Response

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

Fire-and-Forget (with backpressure)

1
2
3
4
5
6

Non-blocking

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

Checking Actor State

Query the actor's state without sending a message:

1
2
3
4
5
6
7
8
9
10

Death Notification

Register to receive notification when an actor stops:

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

Storing Addresses

Keep addresses in your actor state for later use:

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

Type Safety

Addresses are typed, preventing invalid message sends at compile time:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

The type system ensures you can only send messages that the actor can handle. This catches errors at compile time rather than runtime.

Address API Summary

MethodReturnsDescription
send(msg)Result<M::Result>Request-response for sync handler
send_async(msg)Result<M::Result>Request-response for async handler
send_timeout()Result<M::Result>Request-response with timeout
do_send(msg)Result<()>Fire-and-forget, blocks if full
try_send(msg)Result<()>Non-blocking send
is_alive()boolCheck if actor is running
id()ActorIdGet actor's unique ID

Next Steps