syndicate-nim/tests/test_timers.nim

27 lines
740 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 pkg/sys/ioqueue
import syndicate, syndicate/actors/timers
let actor = bootActor("timer-test") do (turn: Turn):
let timers = newDataspace(turn)
spawnTimerActor(timers, turn)
onPublish(turn, timers, ?LaterThan(seconds: 1356100000)):
echo "now in 13th bʼakʼtun"
after(turn, timers, initDuration(seconds = 3)) do (turn: Turn):
echo "third timer expired"
stopActor(turn)
after(turn, timers, initDuration(seconds = 1)) do (turn: Turn):
echo "first timer expired"
after(turn, timers, initDuration(seconds = 2)) do (turn: Turn):
echo "second timer expired"
echo "single run of ioqueue"
ioqueue.run()