Compare commits

...

2 Commits

Author SHA1 Message Date
Emery Hemingway aaaf373468 Add a timeout to runOnce
This allows runOnce to be interwoven with other polling mechanisms.
2024-05-22 04:54:31 +02:00
Emery Hemingway 8f35a1256c Expose root facet of actors 2024-05-22 04:53:59 +02:00
2 changed files with 7 additions and 5 deletions

View File

@ -718,6 +718,8 @@ proc running*(actor): bool =
if not (result or actor.exitReason.isNil):
raise actor.exitReason
proc facet*(actor): Facet = actor.root
proc run(turn: Turn) =
while turn.work.len > 0:
var (facet, act) = turn.work.popFirst()
@ -743,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()
@ -762,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]

View File

@ -1,6 +1,6 @@
# Package
version = "20240507"
version = "20240522"
author = "Emery Hemingway"
description = "Syndicated actors for conversational concurrency"
license = "Unlicense"