From 7b2d59e4cdf80eac7e4c029aafc5240995d5aaad Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Sun, 23 Jul 2023 08:29:45 +0100 Subject: [PATCH] Make runActor sleep on timers to keep asyncdispatch active --- src/syndicate.nim | 11 ++--------- tests/test_timers.nim | 25 +++---------------------- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/src/syndicate.nim b/src/syndicate.nim index 12d6f9d..3095e48 100644 --- a/src/syndicate.nim +++ b/src/syndicate.nim @@ -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) diff --git a/tests/test_timers.nim b/tests/test_timers.nim index cd039b0..d6d1216 100644 --- a/tests/test_timers.nim +++ b/tests/test_timers.nim @@ -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()