Adjust actor API

This commit is contained in:
Emery Hemingway 2024-03-15 10:20:27 +00:00
parent 81ce71d495
commit 50b00827ce
2 changed files with 19 additions and 12 deletions

View File

@ -188,8 +188,3 @@ macro during*(turn: untyped; ds: Cap; pattern: Pattern; publishBody: untyped) =
`callbackProc`
discard inFacet(`turn`) do (`turn`: var Turn):
discard observe(`turn`, `ds`, `pattern`, during(`callbackSym`))
proc runActor*(name: string; bootProc: TurnAction) =
## Boot an actor `Actor` and churn ioqueue once.
discard bootActor(name, bootProc)
actors.run()

View File

@ -704,17 +704,20 @@ proc run(turn: var Turn) =
turnQueue.addLast(move eff)
turn.facet = nil # invalidate the turn
proc runPendingTurns* =
while turnQueue.len > 0:
var turn = turnQueue.popFirst()
# TODO: check if actor is still valid
try: run(turn)
except CatchableError as err:
stderr.writeLine("actor ", turn.actor.name, " threw an error during a turn")
terminateActor(turn, err)
proc run* =
## Run actors to completion
var ready: seq[Continuation]
while true:
while turnQueue.len > 0:
var turn = turnQueue.popFirst()
# TODO: check if actor is still valid
try: run(turn)
except CatchableError as err:
stderr.writeLine("actor ", turn.actor.name, " threw an error during a turn")
terminateActor(turn, err)
runPendingTurns()
ioqueue.poll(ready)
if ready.len == 0: break
while ready.len > 0:
@ -725,6 +728,15 @@ proc run* =
stderr.writeLine "ioqueue continuation threw an error"
raise err
proc runActor*(name: string; bootProc: TurnAction) =
## Boot an actor `Actor` and churn ioqueue.
let actor = bootActor(name, bootProc)
if not actor.exitReason.isNil:
raise actor.exitReason
actors.run()
if not actor.exitReason.isNil:
raise actor.exitReason
type FacetGuard* = object
facet: Facet