syndicate-nim/tests/test_timers.nim

42 lines
1021 B
Nim

# SPDX-FileCopyrightText: ☭ Emery Hemingway
# SPDX-License-Identifier: Unlicense
import std/[os, times]
import pkg/cps
import pkg/sys/ioqueue
import sam/syndicate
import sam/actors/timers
let actor = bootActor("timer-test") do (facet: Facet):
let ds = facet.newDataspace()
let h = publish(ds, toRecord(Symbol"greet", "hello world!"))
retract(ds, h)
facet.onStop do ():
echo "anonymous stop handler was invoked"
let
oneSec = initDuration(seconds = 1)
halfSec = initDuration(milliseconds = 500)
timers = facet.newDataspace()
spawnTimerActor(timers)
timers.after(initDuration(seconds = 1)) do ():
echo "slept one second"
timers.after(initDuration(seconds = 2)) do ():
echo "slept 3 seconds"
timers.after(initDuration(seconds = 3)) do ():
echo "slept six seconds"
stopActor(facet)
timers.after(initDuration(seconds = 20)) do ():
echo "slept twenty seconds"
var progress = true
while not actor.stopped:
if not run(actor):
ioqueue.run()