Cleanup timer example

This commit is contained in:
Emery Hemingway 2024-02-28 19:46:38 +00:00
parent 3ea91ecd24
commit 0a7d129991
1 changed files with 4 additions and 16 deletions

View File

@ -8,31 +8,19 @@ 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()
let timers = facet.newDataspace()
spawnTimerActor(timers)
timers.after(initDuration(seconds = 3)) do ():
echo "slept three seconds"
echo "third timer expired"
stopActor(facet)
timers.after(initDuration(seconds = 1)) do ():
echo "slept one second"
echo "first timer expired"
timers.after(initDuration(seconds = 2)) do ():
echo "slept two seconds"
echo "second timer expired"
var progress = true
while not actor.stopped:
if not run(actor):
ioqueue.run()