syndicate-nim/tests/test_timers.nim

39 lines
1005 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-02-15 10:52:12 +00:00
import pkg/cps
import syndicate
# import syndicate/actors/timers
2023-07-13 14:07:04 +00:00
proc now: float64 = getTime().toUnixFloat()
2024-02-15 10:52:12 +00:00
proc main() {.syndicate.} =
discard activeTurn()
let ds = newDataspace()
let h = publish(ds, "hello world!".toPreserves)
message(ds, "hello world!".toPreserves)
retract(h)
2024-02-15 13:42:58 +00:00
sync(ds)
echo "stopping actor"
stopActor()
echo "actor stopped but still executing?"
2024-02-15 10:52:12 +00:00
#onMessage(ds, grab()) do (v: Value):
# stderr.writeLine "observed message ", v
#[
block:
spawnTimers(ds)
onPublish(ds, grab(LaterThan(seconds: now()+1.0))) do:
stderr.writeLine "slept one second once"
onPublish(ds, grab(LaterThan(seconds: now()+1.0))) do:
stderr.writeLine "slept one second twice"
onPublish(ds, grab(LaterThan(seconds: now()+1.0))) do:
stderr.writeLine "slept one second thrice"
quit()
]#
bootActor("main", whelp main())