From aaaf37346835c458c8d2ce024d5fe77c1142702b Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Wed, 22 May 2024 04:54:31 +0200 Subject: [PATCH] Add a timeout to runOnce This allows runOnce to be interwoven with other polling mechanisms. --- src/syndicate/actors.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/syndicate/actors.nim b/src/syndicate/actors.nim index 26b4e99..2a9929b 100644 --- a/src/syndicate/actors.nim +++ b/src/syndicate/actors.nim @@ -745,16 +745,16 @@ proc runPendingTurns* = terminateActor(turn, err) raise err -proc runOnce*: bool {.discardable.} = +proc runOnce*(timeout = none(Duration)): bool {.discardable.} = ## Run pending turns if there are any, otherwise ## poll for external events and run any resulting turns. ## Return true if any turns have been processed. if turnQueue.len == 0: when defined(solo5): - discard solo5_dispatcher.runOnce() + discard solo5_dispatcher.runOnce(timeout) else: var ready: seq[Continuation] - ioqueue.poll(ready) + ioqueue.poll(ready, timeout) while ready.len > 0: discard trampoline: ready.pop() @@ -764,7 +764,7 @@ proc runOnce*: bool {.discardable.} = proc run* = ## Run actors to completion. when defined(solo5): - while turnQueue.len > 0 or solo5_dispatcher.runOnce(): + while turnQueue.len > 0 or solo5_dispatcher.runOnce(timeout): runPendingTurns() else: var ready: seq[Continuation]