Actors lineages share a handle allocator
For multiple actors to communicate through the same relay they must use unique assertion handles.
This commit is contained in:
parent
b1b0477b8a
commit
91a218f7fb
|
@ -43,7 +43,9 @@ type
|
||||||
future: Future[void]
|
future: Future[void]
|
||||||
name: string
|
name: string
|
||||||
id: ActorId
|
id: ActorId
|
||||||
handleAllocator: Handle
|
handleAllocator: ref Handle
|
||||||
|
# a fresh actor gets a new ref Handle and
|
||||||
|
# all actors spawned from it get the same ref.
|
||||||
root: Facet
|
root: Facet
|
||||||
exitReason: ref Exception
|
exitReason: ref Exception
|
||||||
exitHooks: seq[TurnAction]
|
exitHooks: seq[TurnAction]
|
||||||
|
@ -119,8 +121,8 @@ proc hash*(facet): Hash =
|
||||||
proc hash*(r: Ref): Hash = !$(r.relay.hash !& r.target.unsafeAddr.hash)
|
proc hash*(r: Ref): Hash = !$(r.relay.hash !& r.target.unsafeAddr.hash)
|
||||||
|
|
||||||
proc nextHandle(facet: Facet): Handle =
|
proc nextHandle(facet: Facet): Handle =
|
||||||
inc facet.actor.handleAllocator
|
result = succ(facet.actor.handleAllocator[])
|
||||||
facet.actor.handleAllocator
|
facet.actor.handleAllocator[] = result
|
||||||
|
|
||||||
proc facet*(turn: var Turn): Facet = turn.facet
|
proc facet*(turn: var Turn): Facet = turn.facet
|
||||||
|
|
||||||
|
@ -382,6 +384,7 @@ proc newActor(name: string; bootProc: TurnAction; initialAssertions: OutboundTab
|
||||||
result = Actor(
|
result = Actor(
|
||||||
name: name,
|
name: name,
|
||||||
id: ActorId(seed))
|
id: ActorId(seed))
|
||||||
|
new result.handleAllocator
|
||||||
result.root = newFacet(result, none Facet)
|
result.root = newFacet(result, none Facet)
|
||||||
result.future = newFuture[void]($result)
|
result.future = newFuture[void]($result)
|
||||||
run(
|
run(
|
||||||
|
@ -397,7 +400,8 @@ proc spawn*(name: string; turn: var Turn; bootProc: TurnAction; initialAssertion
|
||||||
var newOutBound: Table[Handle, OutboundAssertion]
|
var newOutBound: Table[Handle, OutboundAssertion]
|
||||||
for key in initialAssertions:
|
for key in initialAssertions:
|
||||||
discard turn.facet.outbound.pop(key, newOutbound[key])
|
discard turn.facet.outbound.pop(key, newOutbound[key])
|
||||||
discard newActor(name, bootProc, newOutBound)
|
let actor = newActor(name, bootProc, newOutBound)
|
||||||
|
actor.handleAllocator = turn.facet.actor.handleAllocator
|
||||||
|
|
||||||
proc newInertRef*(): Ref =
|
proc newInertRef*(): Ref =
|
||||||
let a = bootActor("inert") do (turn: var Turn): turn.stop()
|
let a = bootActor("inert") do (turn: var Turn): turn.stop()
|
||||||
|
|
Loading…
Reference in New Issue