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,15 +189,18 @@ 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) =
var next = Turn(facet: target) if target.actor == turn.facet.actor:
assert not target.isNil turn.work.addLast((target, act,))
next.work.addLast((target, act,)) else:
when tracing: var next = Turn(facet: target)
next.desc.id = nextTurnId() assert not target.isNil
next.desc.cause = TurnCause(orKind: TurnCauseKind.turn) next.work.addLast((target, act,))
next.desc.cause.turn.id = turn.desc.id when tracing:
turn.effects.add next next.desc.id = nextTurnId()
next.desc.cause = TurnCause(orKind: TurnCauseKind.turn)
next.desc.cause.turn.id = turn.desc.id
turn.effects.add next
type Bindings = Table[Value, Value] type Bindings = Table[Value, Value]
@ -354,9 +357,8 @@ 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) =
e.sync(turn, peer) e.sync(turn, peer)
@ -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