Messages

Type-safe communication between actors.

What is a Message?

Messages are the only way actors communicate. Each message type defines what data it carries and what type of response it expects:

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

Message Requirements

Messages must satisfy these trait bounds:

TraitWhy
SendMessages may cross thread boundaries
'staticMessages must outlive the send operation
Result: SendResponse also crosses thread boundaries
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

Sending Messages

Cineyma provides three patterns for sending messages:

1. Request-Response (send)

Wait for and receive the response:

1
2
3
4
5
6
7
8
9

2. Fire-and-Forget with Backpressure (do_send)

Send without waiting for response, but respect mailbox limits:

1
2
3
4
5
6
7
8
9

3. Non-blocking Send (try_send)

Send immediately or fail if mailbox is full:

1
2
3
4
5
6
7
8
9
10
11

Method Comparison

MethodWaits for ResponseBlocks on FullUse Case
send()YesYesNeed the result
do_send()NoYesFire-and-forget, reliable
try_send()NoNoNon-blocking, lossy OK

Built-in Messages

Cineyma provides some special messages:

1
2
3
4
5
6
7
8
9

Message Design Patterns

Command Pattern

Messages that request an action:

1
2
3
4
5
6
7
8
9
10

Query Pattern

Messages that request data:

1
2
3
4
5
6
7
8
9
10

Event Pattern

Notifications that don't need responses:

1
2
3
4
5
6
7
8
9
10

Error Handling

Handle send errors properly:

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

Next Steps