Queue effects to the local actor to the local turn
This commit is contained in:
parent
20d7420b81
commit
7eb9537df1
|
@ -189,15 +189,18 @@ proc run*(facet: Facet; action: TurnAction) = queueTurn(facet, action)
|
|||
|
||||
proc facet*(turn: Turn): Facet = turn.facet
|
||||
|
||||
proc queueEffect*(turn: Turn; target: Facet; act: TurnAction) =
|
||||
var next = Turn(facet: target)
|
||||
assert not target.isNil
|
||||
next.work.addLast((target, act,))
|
||||
when tracing:
|
||||
next.desc.id = nextTurnId()
|
||||
next.desc.cause = TurnCause(orKind: TurnCauseKind.turn)
|
||||
next.desc.cause.turn.id = turn.desc.id
|
||||
turn.effects.add next
|
||||
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)
|
||||
assert not target.isNil
|
||||
next.work.addLast((target, act,))
|
||||
when tracing:
|
||||
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]
|
||||
|
||||
|
@ -354,9 +357,8 @@ proc message*(turn: var Turn; r: Cap; v: Value) =
|
|||
queueEffect(turn, r.relay) do (turn: var Turn):
|
||||
r.target.message(turn, AssertionRef(value: a))
|
||||
|
||||
proc message*[T](turn: Turn; r: Cap; v: T) =
|
||||
queueEffect(turn, r.relay) do (turn: Turn):
|
||||
message(turn, r, v.toPreserves)
|
||||
proc message*[T](turn: var Turn; r: Cap; v: T) =
|
||||
message(turn, r, v.toPreserves)
|
||||
|
||||
proc sync(turn: var Turn; e: Entity; peer: Cap) =
|
||||
e.sync(turn, peer)
|
||||
|
@ -641,8 +643,8 @@ proc run(turn: var Turn) =
|
|||
trace(turn.facet.actor, act)
|
||||
turn.facet = nil # invalidate the turn
|
||||
# TODO: catch exceptions here
|
||||
while turn.effects.len > 0:
|
||||
turnQueue.addLast turn.effects.pop()
|
||||
for eff in turn.effects.mitems:
|
||||
turnQueue.addLast(move eff)
|
||||
|
||||
proc run* =
|
||||
## Run actors to completion
|
||||
|
|
Loading…
Reference in New Issue