Fix runActor exit

This commit is contained in:
Emery Hemingway 2023-10-26 13:13:03 +01:00
parent 843252ad61
commit 577490701a
2 changed files with 9 additions and 12 deletions

View File

@ -192,9 +192,8 @@ type DeprecatedBootProc = proc (ds: Cap; turn: var Turn) {.gcsafe.}
proc runActor*(name: string; bootProc: BootProc) =
## Run an `Actor` to completion.
let actor = bootDataspace(name, bootProc)
while not actor.future.finished:
while actor.running:
waitFor sleepAsync(500)
read(actor.future)
proc runActor*(name: string; bootProc: DeprecatedBootProc) {.deprecated.} =
## Run an `Actor` to completion.

View File

@ -54,7 +54,6 @@ type
OutboundTable = Table[Handle, OutboundAssertion]
Actor* = ref object
future: Future[void]
name: string
handleAllocator: ref Handle
# a fresh actor gets a new ref Handle and
@ -63,7 +62,7 @@ type
exitReason: ref Exception
exitHooks: seq[TurnAction]
id: ActorId
exiting: bool
exiting, exited: bool
when tracing:
turnIdAllocator: ref TurnId
traceStream: FileStream
@ -440,7 +439,6 @@ proc newActor(name: string; handleAlloc: ref Handle): Actor =
handleAllocator: handleAlloc,
)
result.root = newFacet(result, nil)
result.future = newFuture[void]($result)
when tracing:
var act = ActorActivation[void](orKind: ActorActivationKind.start)
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) =
if not actor.exiting:
actor.exiting = true
actor.exitReason = reason
when tracing:
var act = ActorActivation[void](orKind: ActorActivationKind.stop)
if not reason.isNil:
act.stop.status = ExitStatus(orKind: ExitStatusKind.Error)
act.stop.status.error.message = reason.msg
trace(actor, act)
actor.exiting = true
actor.exitReason = reason
for hook in actor.exitHooks: hook(turn)
proc finish(turn: var Turn) =
actor.root.terminate(turn, reason.isNil)
if actor.exitReason.isNil:
actor.future.complete()
else:
actor.future.fail actor.exitReason
actor.exited = true
callSoon do ():
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.}) =
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