43 lines
1.0 KiB
Nim
43 lines
1.0 KiB
Nim
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
|
# SPDX-License-Identifier: Unlicense
|
|
|
|
import std/times
|
|
import pkg/cps
|
|
import syndicate
|
|
|
|
# import syndicate/actors/timers
|
|
|
|
proc now: float64 = getTime().toUnixFloat()
|
|
|
|
proc main() {.syndicate.} =
|
|
let ds = newDataspace()
|
|
let h = publish(ds, "hello world!".toPreserves)
|
|
message(ds, "hello world!".toPreserves)
|
|
retract(h)
|
|
sync(ds)
|
|
|
|
onStop:
|
|
echo "anonymous stop handler was invoked"
|
|
|
|
echo "stopping actor"
|
|
stopActor()
|
|
echo "actor stopped but still executing?"
|
|
|
|
#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"
|
|
stopActor()
|
|
]#
|
|
|
|
|
|
bootActor("main", whelp main())
|