De-async actors
This commit is contained in:
parent
1ce96560f4
commit
0cee6670c9
|
@ -3,7 +3,7 @@
|
|||
|
||||
## This module implements the `Syndicate DSL <https://syndicate-lang.org/doc/syndicate/>`_.
|
||||
|
||||
import std/[asyncdispatch, macros, tables, typetraits]
|
||||
import std/[macros, tables, typetraits]
|
||||
|
||||
import preserves
|
||||
export fromPreserves, toPreserves
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
import std/[asyncfutures, hashes, monotimes, options, sets, tables, times]
|
||||
import std/[hashes, monotimes, options, sets, tables, times]
|
||||
import preserves
|
||||
import ../syndicate/protocols/[protocol, sturdy]
|
||||
|
||||
|
@ -492,13 +492,14 @@ proc terminate(actor; turn; reason: ref Exception) =
|
|||
proc finish(turn: var Turn) =
|
||||
actor.root.terminate(turn, reason.isNil)
|
||||
actor.exited = true
|
||||
callSoon do ():
|
||||
block:
|
||||
run(actor.root, finish, true)
|
||||
|
||||
proc terminate*(facet; e: ref Exception) =
|
||||
run(facet.actor.root) do (turn: var Turn):
|
||||
facet.actor.terminate(turn, e)
|
||||
|
||||
#[
|
||||
proc asyncCheck*(facet: Facet; fut: FutureBase) =
|
||||
## Sets a callback on `fut` which propagates exceptions to `facet`.
|
||||
addCallback(fut) do ():
|
||||
|
@ -507,13 +508,14 @@ proc asyncCheck*(facet: Facet; fut: FutureBase) =
|
|||
proc asyncCheck*(turn; fut: FutureBase) =
|
||||
## Sets a callback on `fut` which propagates exceptions to the facet of `turn`.
|
||||
asyncCheck(turn.facet, fut)
|
||||
]#
|
||||
|
||||
template tryFacet(facet; body: untyped) =
|
||||
try: body
|
||||
except CatchableError as err: terminate(facet, err)
|
||||
|
||||
proc run*(facet; action: TurnAction; zombieTurn = false) =
|
||||
if zombieTurn or (facet.actor.exitReason.isNil and facet.isAlive):
|
||||
if true and zombieTurn or (facet.actor.exitReason.isNil and facet.isAlive):
|
||||
tryFacet(facet):
|
||||
var queues = newTable[Facet, seq[TurnAction]]()
|
||||
block:
|
||||
|
@ -530,6 +532,7 @@ proc run*(cap: Cap; action: TurnAction) =
|
|||
## Convenience proc to run a `TurnAction` in the scope of a `Cap`.
|
||||
run(cap.relay, action)
|
||||
|
||||
#[
|
||||
proc addCallback*(fut: FutureBase; facet: Facet; act: TurnAction) =
|
||||
## Add a callback to a `Future` that will be called at a later `Turn`
|
||||
## within the context of `facet`.
|
||||
|
@ -562,6 +565,7 @@ proc addCallback*[T](fut: Future[T]; turn: var Turn; act: proc (t: var Turn, x:
|
|||
turn.desc.cause = TurnCause(orKind: TurnCauseKind.external)
|
||||
turn.desc.cause.external.description = "Future".toPreserves
|
||||
act(turn, read fut)
|
||||
]#
|
||||
|
||||
proc stop*(turn: var Turn, facet: Facet) =
|
||||
if facet.parent.isNil:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
import std/[asyncdispatch, options, tables]
|
||||
import std/[options, tables]
|
||||
from std/os import getEnv, `/`
|
||||
import preserves
|
||||
import ../syndicate, /capabilities, ./durings, ./membranes, ./protocols/[gatekeeper, protocol, sturdy, transportAddress]
|
||||
|
|
Loading…
Reference in New Issue