2023-07-13 14:07:04 +00:00
|
|
|
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
|
|
|
|
# SPDX-License-Identifier: Unlicense
|
|
|
|
|
|
2023-07-23 07:29:45 +00:00
|
|
|
|
import std/times
|
2024-04-17 14:39:28 +00:00
|
|
|
|
import syndicate, syndicate/drivers/timers, preserves
|
|
|
|
|
|
|
|
|
|
var passCount = 0
|
2023-07-13 14:07:04 +00:00
|
|
|
|
|
2024-04-30 10:52:40 +00:00
|
|
|
|
runActor("timer-test") do (turn: Turn):
|
2024-03-01 14:10:40 +00:00
|
|
|
|
let timers = newDataspace(turn)
|
2024-04-03 09:59:47 +00:00
|
|
|
|
spawnTimerDriver(turn, timers)
|
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-04-17 14:39:28 +00:00
|
|
|
|
inc passCount
|
2024-03-01 14:10:40 +00:00
|
|
|
|
|
2024-04-30 10:52:40 +00:00
|
|
|
|
after(turn, timers, initDuration(seconds = 3)) do (turn: Turn):
|
2024-03-01 14:10:40 +00:00
|
|
|
|
echo "third timer expired"
|
2024-04-17 14:39:28 +00:00
|
|
|
|
assert passCount == 3
|
|
|
|
|
inc passCount
|
2024-03-01 14:10:40 +00:00
|
|
|
|
|
2024-04-30 10:52:40 +00:00
|
|
|
|
after(turn, timers, initDuration(seconds = 1)) do (turn: Turn):
|
2024-03-01 14:10:40 +00:00
|
|
|
|
echo "first timer expired"
|
2024-04-17 14:39:28 +00:00
|
|
|
|
assert passCount == 1
|
|
|
|
|
inc passCount
|
2024-03-01 14:10:40 +00:00
|
|
|
|
|
2024-04-30 10:52:40 +00:00
|
|
|
|
after(turn, timers, initDuration(seconds = 2)) do (turn: Turn):
|
2024-03-01 14:10:40 +00:00
|
|
|
|
echo "second timer expired"
|
2024-04-17 14:39:28 +00:00
|
|
|
|
assert passCount == 2
|
|
|
|
|
inc passCount
|
|
|
|
|
|
|
|
|
|
doAssert passCount == 4, $passCount
|