syndicate-nim/tests/test_timers.nim

47 lines
1.2 KiB
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
2024-02-19 22:40:40 +00:00
import sam/syndicate
2024-02-15 10:52:12 +00:00
2024-02-19 22:40:40 +00:00
import sam/actors/timers
2023-07-13 14:07:04 +00:00
proc now: float64 = getTime().toUnixFloat()
2024-02-18 00:56:59 +00:00
runActor("timer-test") do (root: Facet):
2024-02-19 22:40:40 +00:00
echo "actor calls boot proc with root facte ", root
2024-02-16 12:58:17 +00:00
2024-02-19 22:40:40 +00:00
let ds = root.newDataspace()
echo "new dataspace ", ds
let h = publish(ds, "hello world!".toPreserves)
echo "published to handle ", h
2024-02-16 12:58:17 +00:00
2024-02-19 22:40:40 +00:00
onMessage(ds, grab()) do (v: Value):
2024-02-18 00:56:59 +00:00
stderr.writeLine "observed message ", v
2024-02-15 14:34:13 +00:00
2024-02-19 22:40:40 +00:00
message(ds, "hello world!".toPreserves)
echo "sent a message"
retract(ds, h)
echo "retracted handle ", h
# facet.sync(ds)
2024-02-18 00:56:59 +00:00
2024-02-19 22:40:40 +00:00
root.onStop:
2024-02-15 19:50:11 +00:00
echo "anonymous stop handler was invoked"
2024-02-15 14:34:13 +00:00
2024-02-15 13:42:58 +00:00
echo "stopping actor"
2024-02-19 22:40:40 +00:00
root.stopActor()
2024-02-15 13:42:58 +00:00
echo "actor stopped but still executing?"
2024-02-15 10:52:12 +00:00
#[
block:
2024-02-16 12:58:17 +00:00
# spawnTimers(ds)
2024-02-15 10:52:12 +00:00
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"
2024-02-15 14:34:13 +00:00
stopActor()
2024-02-15 10:52:12 +00:00
]#