Make runActor sleep on timers to keep asyncdispatch active
This commit is contained in:
parent
7f903a14d7
commit
7b2d59e4cd
|
@ -192,16 +192,9 @@ macro during*(turn: untyped; ds: Ref; pattern: Pattern; publishBody: untyped) =
|
|||
|
||||
type BootProc = proc (ds: Ref; turn: var Turn) {.gcsafe.}
|
||||
|
||||
from std/os import getEnv
|
||||
|
||||
proc runActor*(name: string; bootProc: BootProc) =
|
||||
## Run an `Actor` to completion.
|
||||
let actor = bootDataspace(name, bootProc)
|
||||
if getEnv"SYNDICATE_DEBUG" == "":
|
||||
while not actor.future.finished:
|
||||
poll()
|
||||
else:
|
||||
while not actor.future.finished:
|
||||
stderr.writeLine("Polling ", name, " actor…")
|
||||
poll()
|
||||
while not actor.future.finished:
|
||||
waitFor sleepAsync(500)
|
||||
read(actor.future)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
import std/[asyncdispatch, os, times]
|
||||
import preserves, syndicate, syndicate/actors/timers
|
||||
import std/times
|
||||
import syndicate, syndicate/actors/timers
|
||||
|
||||
proc now: float64 = getTime().toUnixFloat()
|
||||
|
||||
proc testTimers(turn: var Turn; ds: Ref) =
|
||||
runActor("test_timers") do (ds: Ref; turn: var Turn):
|
||||
onPublish(turn, ds, ?LaterThan(seconds: now()+1.0)) do:
|
||||
stderr.writeLine "slept one second once"
|
||||
onPublish(turn, ds, ?LaterThan(seconds: now()+1.0)) do:
|
||||
|
@ -15,22 +15,3 @@ proc testTimers(turn: var Turn; ds: Ref) =
|
|||
stderr.writeLine "slept one second thrice"
|
||||
quit()
|
||||
spawnTimers(turn, ds)
|
||||
|
||||
type Args {.preservesDictionary.} = object
|
||||
dataspace: Ref
|
||||
|
||||
proc asInferior: bool =
|
||||
commandLineParams() == @["--inferior"]
|
||||
|
||||
if asInferior():
|
||||
stderr.writeLine "connect stdio"
|
||||
runActor("test_timers") do (root: Ref; turn: var Turn):
|
||||
connectStdio(root, turn)
|
||||
during(turn, root, ?Args) do (ds: Ref):
|
||||
testTimers(turn, ds)
|
||||
else:
|
||||
stderr.writeLine "use local dataspace"
|
||||
discard bootDataspace("test_timers") do (ds: Ref; turn: var Turn):
|
||||
testTimers(turn, ds)
|
||||
|
||||
for i in 0..10: poll()
|
||||
|
|
Loading…
Reference in New Issue