Add runOnce proc
This is useful for forcing progress when embedding Syndicate in contexts that don't expose turn semantics.
This commit is contained in:
parent
5fc371d187
commit
c99f0a60ab
|
@ -736,8 +736,24 @@ proc runPendingTurns* =
|
||||||
terminateActor(turn, err)
|
terminateActor(turn, err)
|
||||||
raise err
|
raise err
|
||||||
|
|
||||||
|
proc runOnce*: 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()
|
||||||
|
else:
|
||||||
|
var ready: seq[Continuation]
|
||||||
|
ioqueue.poll(ready)
|
||||||
|
while ready.len > 0:
|
||||||
|
discard trampoline:
|
||||||
|
ready.pop()
|
||||||
|
result = turnQueue.len > 0
|
||||||
|
runPendingTurns()
|
||||||
|
|
||||||
proc run* =
|
proc run* =
|
||||||
## Run actors to completion
|
## Run actors to completion.
|
||||||
when defined(solo5):
|
when defined(solo5):
|
||||||
while turnQueue.len > 0 or solo5_dispatcher.runOnce():
|
while turnQueue.len > 0 or solo5_dispatcher.runOnce():
|
||||||
runPendingTurns()
|
runPendingTurns()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "20240422"
|
version = "20240424"
|
||||||
author = "Emery Hemingway"
|
author = "Emery Hemingway"
|
||||||
description = "Syndicated actors for conversational concurrency"
|
description = "Syndicated actors for conversational concurrency"
|
||||||
license = "Unlicense"
|
license = "Unlicense"
|
||||||
|
|
Loading…
Reference in New Issue