Adjust actor API
This commit is contained in:
parent
81ce71d495
commit
50b00827ce
|
@ -188,8 +188,3 @@ macro during*(turn: untyped; ds: Cap; pattern: Pattern; publishBody: untyped) =
|
||||||
`callbackProc`
|
`callbackProc`
|
||||||
discard inFacet(`turn`) do (`turn`: var Turn):
|
discard inFacet(`turn`) do (`turn`: var Turn):
|
||||||
discard observe(`turn`, `ds`, `pattern`, during(`callbackSym`))
|
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()
|
|
||||||
|
|
|
@ -704,17 +704,20 @@ proc run(turn: var Turn) =
|
||||||
turnQueue.addLast(move eff)
|
turnQueue.addLast(move eff)
|
||||||
turn.facet = nil # invalidate the turn
|
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* =
|
proc run* =
|
||||||
## Run actors to completion
|
## Run actors to completion
|
||||||
var ready: seq[Continuation]
|
var ready: seq[Continuation]
|
||||||
while true:
|
while true:
|
||||||
while turnQueue.len > 0:
|
runPendingTurns()
|
||||||
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)
|
|
||||||
ioqueue.poll(ready)
|
ioqueue.poll(ready)
|
||||||
if ready.len == 0: break
|
if ready.len == 0: break
|
||||||
while ready.len > 0:
|
while ready.len > 0:
|
||||||
|
@ -725,6 +728,15 @@ proc run* =
|
||||||
stderr.writeLine "ioqueue continuation threw an error"
|
stderr.writeLine "ioqueue continuation threw an error"
|
||||||
raise err
|
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
|
type FacetGuard* = object
|
||||||
facet: Facet
|
facet: Facet
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue