Fix runActor exit
This commit is contained in:
parent
843252ad61
commit
577490701a
|
@ -192,9 +192,8 @@ type DeprecatedBootProc = proc (ds: Cap; turn: var Turn) {.gcsafe.}
|
||||||
proc runActor*(name: string; bootProc: BootProc) =
|
proc runActor*(name: string; bootProc: BootProc) =
|
||||||
## Run an `Actor` to completion.
|
## Run an `Actor` to completion.
|
||||||
let actor = bootDataspace(name, bootProc)
|
let actor = bootDataspace(name, bootProc)
|
||||||
while not actor.future.finished:
|
while actor.running:
|
||||||
waitFor sleepAsync(500)
|
waitFor sleepAsync(500)
|
||||||
read(actor.future)
|
|
||||||
|
|
||||||
proc runActor*(name: string; bootProc: DeprecatedBootProc) {.deprecated.} =
|
proc runActor*(name: string; bootProc: DeprecatedBootProc) {.deprecated.} =
|
||||||
## Run an `Actor` to completion.
|
## Run an `Actor` to completion.
|
||||||
|
|
|
@ -54,7 +54,6 @@ type
|
||||||
OutboundTable = Table[Handle, OutboundAssertion]
|
OutboundTable = Table[Handle, OutboundAssertion]
|
||||||
|
|
||||||
Actor* = ref object
|
Actor* = ref object
|
||||||
future: Future[void]
|
|
||||||
name: string
|
name: string
|
||||||
handleAllocator: ref Handle
|
handleAllocator: ref Handle
|
||||||
# a fresh actor gets a new ref Handle and
|
# a fresh actor gets a new ref Handle and
|
||||||
|
@ -63,7 +62,7 @@ type
|
||||||
exitReason: ref Exception
|
exitReason: ref Exception
|
||||||
exitHooks: seq[TurnAction]
|
exitHooks: seq[TurnAction]
|
||||||
id: ActorId
|
id: ActorId
|
||||||
exiting: bool
|
exiting, exited: bool
|
||||||
when tracing:
|
when tracing:
|
||||||
turnIdAllocator: ref TurnId
|
turnIdAllocator: ref TurnId
|
||||||
traceStream: FileStream
|
traceStream: FileStream
|
||||||
|
@ -440,7 +439,6 @@ proc newActor(name: string; handleAlloc: ref Handle): Actor =
|
||||||
handleAllocator: handleAlloc,
|
handleAllocator: handleAlloc,
|
||||||
)
|
)
|
||||||
result.root = newFacet(result, nil)
|
result.root = newFacet(result, nil)
|
||||||
result.future = newFuture[void]($result)
|
|
||||||
when tracing:
|
when tracing:
|
||||||
var act = ActorActivation[void](orKind: ActorActivationKind.start)
|
var act = ActorActivation[void](orKind: ActorActivationKind.start)
|
||||||
act.start.actorName = Name[void](orKind: NameKind.named)
|
act.start.actorName = Name[void](orKind: NameKind.named)
|
||||||
|
@ -485,21 +483,18 @@ proc atExit*(actor; action) = actor.exitHooks.add action
|
||||||
|
|
||||||
proc terminate(actor; turn; reason: ref Exception) =
|
proc terminate(actor; turn; reason: ref Exception) =
|
||||||
if not actor.exiting:
|
if not actor.exiting:
|
||||||
|
actor.exiting = true
|
||||||
|
actor.exitReason = reason
|
||||||
when tracing:
|
when tracing:
|
||||||
var act = ActorActivation[void](orKind: ActorActivationKind.stop)
|
var act = ActorActivation[void](orKind: ActorActivationKind.stop)
|
||||||
if not reason.isNil:
|
if not reason.isNil:
|
||||||
act.stop.status = ExitStatus(orKind: ExitStatusKind.Error)
|
act.stop.status = ExitStatus(orKind: ExitStatusKind.Error)
|
||||||
act.stop.status.error.message = reason.msg
|
act.stop.status.error.message = reason.msg
|
||||||
trace(actor, act)
|
trace(actor, act)
|
||||||
actor.exiting = true
|
|
||||||
actor.exitReason = reason
|
|
||||||
for hook in actor.exitHooks: hook(turn)
|
for hook in actor.exitHooks: hook(turn)
|
||||||
proc finish(turn: var Turn) =
|
proc finish(turn: var Turn) =
|
||||||
actor.root.terminate(turn, reason.isNil)
|
actor.root.terminate(turn, reason.isNil)
|
||||||
if actor.exitReason.isNil:
|
actor.exited = true
|
||||||
actor.future.complete()
|
|
||||||
else:
|
|
||||||
actor.future.fail actor.exitReason
|
|
||||||
callSoon do ():
|
callSoon do ():
|
||||||
run(actor.root, finish, true)
|
run(actor.root, finish, true)
|
||||||
|
|
||||||
|
@ -603,4 +598,7 @@ proc newCap*(turn; e: Entity): Cap =
|
||||||
proc sync*(turn, refer: Cap, cb: proc(t: Turn) {.gcsafe.}) =
|
proc sync*(turn, refer: Cap, cb: proc(t: Turn) {.gcsafe.}) =
|
||||||
raiseAssert "not implemented"
|
raiseAssert "not implemented"
|
||||||
|
|
||||||
proc future*(actor): Future[void] = actor.future
|
proc running*(actor): bool =
|
||||||
|
result = not actor.exited
|
||||||
|
if not (result or actor.exitReason.isNil):
|
||||||
|
raise actor.exitReason
|
||||||
|
|
Loading…
Reference in New Issue