Actors

The fundamental building block of Cineyma applications.

What is an Actor?

An actor is an isolated unit of computation that:

  • Encapsulates state — Its internal state is completely private
  • Processes messages sequentially — One message at a time, no data races
  • Communicates via messages — No shared memory, only message passing
  • Can spawn child actors — Form supervision hierarchies

Defining an Actor

Any struct can become an actor by implementing the Actor trait:

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

Note: Actors must be Send + 'static to be spawned across async boundaries. This is enforced at compile time.

Actor Lifecycle

Every actor goes through a defined lifecycle:

Actor lifecycle state transitions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

Spawning Actors

Actors can be spawned from the actor system or from other actors:

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

Spawning Child Actors

Actors can spawn children that form a supervision hierarchy:

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
30
31
32
33

Important: When a parent actor stops, all its children are automatically stopped too. This enables clean shutdown of actor hierarchies.

Stopping Actors

Actors can be stopped in several ways:

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

Actor Identity

Every actor has a unique ActorId:

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

Best Practices

Keep actors focused

Each actor should have a single responsibility. Split complex logic across multiple actors.

Use supervision

Build fault-tolerant systems by organizing actors into supervision hierarchies.

Size mailboxes appropriately

Use larger mailboxes for high-throughput actors, smaller for low-traffic ones.

Don't share state directly

Never share mutable state between actors. Use messages instead.

Avoid blocking in handlers

Use AsyncHandler for I/O operations to avoid blocking other messages.

Next Steps