Timers

Schedule delayed and periodic messages to actors.

Overview

cineyma provides two timer functions through the actor context:

  • run_later — Send a message after a delay (one-shot)
  • run_interval — Send a message repeatedly at fixed intervals

Delayed Messages (run_later)

Send a message to yourself after a specified duration:

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

Periodic Messages (run_interval)

Send a message repeatedly at fixed intervals:

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

Timer Handles & Cancellation

Both timer functions return a TimerHandle that can be used to cancel the timer:

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

Timers are automatically cancelled when an actor stops. You only need to manually cancel if you want to stop a timer while the actor is still running.

Practical Examples

Request Timeout

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

Debouncing

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

Periodic Cleanup

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

Next Steps