Context
The actor's runtime environment and capabilities.
What is Context?
Context<A> is passed to every handler and lifecycle hook. It provides the actor with:
- →Access to its own address
- →Ability to spawn child actors
- →Timer scheduling (delayed and periodic)
- →Stream attachment
- →Death watch for other actors
- →Self-stop capability
Self Reference
Get your own address and ID:
1
2
3
4
5
6
7
8
9
10
11
12
Spawning Child Actors
Create supervised child actors:
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
Timers
Schedule delayed and periodic messages:
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
34
35
36
37
38
39
40
41
42
Timer Cancellation
Cancel timers before they fire:
1
2
3
4
5
6
7
8
9
10
11
12
Stream Attachment
Attach async streams for continuous processing:
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
Death Watch
Monitor other actors and react to their termination:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Stopping the Actor
Gracefully stop from within the actor:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Context API Summary
| Method | Description |
|---|---|
address() | Get this actor's address |
id() | Get this actor's unique ID |
stop() | Stop this actor gracefully |
spawn_child() | Spawn a supervised child actor |
run_later() | Schedule a one-shot timer |
run_interval() | Schedule a repeating timer |
add_stream() | Attach an async stream |
watch() | Watch another actor for termination |
