syndicate-nim/tests/test_timers.nim

27 lines
756 B
Nim
Raw Normal View History

2023-07-13 14:07:04 +00:00
# SPDX-FileCopyrightText: ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
import std/times
2024-03-01 14:10:40 +00:00
import pkg/sys/ioqueue
import syndicate, syndicate/actors/timers
2023-07-13 14:07:04 +00:00
2024-03-08 15:40:07 +00:00
let actor = bootActor("timer-test") do (turn: var Turn):
2024-03-01 14:10:40 +00:00
let timers = newDataspace(turn)
spawnTimerActor(timers, turn)
2023-07-13 14:07:04 +00:00
2024-03-01 14:10:40 +00:00
onPublish(turn, timers, ?LaterThan(seconds: 1356100000)):
echo "now in 13th bʼakʼtun"
2024-03-08 15:40:07 +00:00
after(turn, timers, initDuration(seconds = 3)) do (turn: var Turn):
2024-03-01 14:10:40 +00:00
echo "third timer expired"
stopActor(turn)
2024-03-08 15:40:07 +00:00
after(turn, timers, initDuration(seconds = 1)) do (turn: var Turn):
2024-03-01 14:10:40 +00:00
echo "first timer expired"
2024-03-08 15:40:07 +00:00
after(turn, timers, initDuration(seconds = 2)) do (turn: var Turn):
2024-03-01 14:10:40 +00:00
echo "second timer expired"
echo "single run of ioqueue"
ioqueue.run()