syndicate-nim/tests/test_timers.nim

33 lines
875 B
Nim
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# SPDX-FileCopyrightText: ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
import std/times
import syndicate, syndicate/drivers/timers, preserves
var passCount = 0
runActor("timer-test") do (turn: var Turn):
let timers = newDataspace(turn)
spawnTimerDriver(turn, timers)
onPublish(turn, timers, ?LaterThan(seconds: 1356100000)):
echo "now in 13th bʼakʼtun"
inc passCount
after(turn, timers, initDuration(seconds = 3)) do (turn: var Turn):
echo "third timer expired"
assert passCount == 3
inc passCount
after(turn, timers, initDuration(seconds = 1)) do (turn: var Turn):
echo "first timer expired"
assert passCount == 1
inc passCount
after(turn, timers, initDuration(seconds = 2)) do (turn: var Turn):
echo "second timer expired"
assert passCount == 2
inc passCount
doAssert passCount == 4, $passCount