Queue effects to the local actor to the local turn

This commit is contained in:
Emery Hemingway 2024-03-08 16:09:55 +00:00
parent cf395dbfa4
commit b8c1bec9cf
1 changed files with 16 additions and 14 deletions

View File

@ -189,7 +189,10 @@ proc run*(facet: Facet; action: TurnAction) = queueTurn(facet, action)
proc facet*(turn: Turn): Facet = turn.facet proc facet*(turn: Turn): Facet = turn.facet
proc queueEffect*(turn: Turn; target: Facet; act: TurnAction) = proc queueEffect*(turn: var Turn; target: Facet; act: TurnAction) =
if target.actor == turn.facet.actor:
turn.work.addLast((target, act,))
else:
var next = Turn(facet: target) var next = Turn(facet: target)
assert not target.isNil assert not target.isNil
next.work.addLast((target, act,)) next.work.addLast((target, act,))
@ -354,8 +357,7 @@ proc message*(turn: var Turn; r: Cap; v: Value) =
queueEffect(turn, r.relay) do (turn: var Turn): queueEffect(turn, r.relay) do (turn: var Turn):
r.target.message(turn, AssertionRef(value: a)) r.target.message(turn, AssertionRef(value: a))
proc message*[T](turn: Turn; r: Cap; v: T) = proc message*[T](turn: var Turn; r: Cap; v: T) =
queueEffect(turn, r.relay) do (turn: Turn):
message(turn, r, v.toPreserves) message(turn, r, v.toPreserves)
proc sync(turn: var Turn; e: Entity; peer: Cap) = proc sync(turn: var Turn; e: Entity; peer: Cap) =
@ -641,8 +643,8 @@ proc run(turn: var Turn) =
trace(turn.facet.actor, act) trace(turn.facet.actor, act)
turn.facet = nil # invalidate the turn turn.facet = nil # invalidate the turn
# TODO: catch exceptions here # TODO: catch exceptions here
while turn.effects.len > 0: for eff in turn.effects.mitems:
turnQueue.addLast turn.effects.pop() turnQueue.addLast(move eff)
proc run* = proc run* =
## Run actors to completion ## Run actors to completion