Return an Actor from spawn
This commit is contained in:
parent
248d34ce69
commit
4b29fc009b
|
@ -20,7 +20,7 @@ export patterns
|
|||
export Actor, Assertion, Facet, Handle, Ref, Symbol, Turn, TurnAction,
|
||||
`$`, addCallback, analyse, asyncCheck, bootDataspace,
|
||||
facet, future, inFacet, message, newDataspace, onStop, publish,
|
||||
retract, replace, run, stop, unembed, unpackLiterals
|
||||
retract, replace, run, spawn, stop, unembed, unpackLiterals
|
||||
|
||||
proc `!`*(typ: static typedesc): Pattern {.inline.} =
|
||||
patterns.dropType(typ)
|
||||
|
|
|
@ -428,14 +428,15 @@ proc inFacet*(turn: var Turn; bootProc: TurnAction): Facet =
|
|||
|
||||
proc facet*(turn: var Turn; bootProc: TurnAction): Facet {.deprecated.} = inFacet(turn, bootProc)
|
||||
|
||||
proc newActor(name: string): Actor =
|
||||
proc newActor(name: string; handleAlloc: ref Handle): Actor =
|
||||
let
|
||||
now = getTime()
|
||||
seed = now.toUnix * 1_000_000_000 + now.nanosecond
|
||||
result = Actor(
|
||||
name: name,
|
||||
id: ActorId(seed))
|
||||
new result.handleAllocator
|
||||
id: ActorId(seed),
|
||||
handleAllocator: handleAlloc,
|
||||
)
|
||||
result.root = newFacet(result, nil)
|
||||
result.future = newFuture[void]($result)
|
||||
when tracing:
|
||||
|
@ -449,8 +450,7 @@ proc run(actor; bootProc: TurnAction; initialAssertions: OutboundTable) =
|
|||
|
||||
proc bootActor*(name: string; bootProc: TurnAction): Actor =
|
||||
var initialAssertions: OutboundTable
|
||||
result = newActor(name)
|
||||
new result.handleAllocator
|
||||
result = newActor(name, new(ref Handle))
|
||||
when tracing:
|
||||
new result.turnIdAllocator
|
||||
let path = getEnv("SYNDICATE_TRACE_FILE", "/tmp/" & name & ".trace.pr")
|
||||
|
@ -460,13 +460,12 @@ proc bootActor*(name: string; bootProc: TurnAction): Actor =
|
|||
else: result.traceStream = openFileStream(path, fmWrite)
|
||||
run(result, bootProc, initialAssertions)
|
||||
|
||||
proc spawn*(name: string; turn: var Turn; bootProc: TurnAction; initialAssertions = initHashSet[Handle]()) =
|
||||
proc spawn*(name: string; turn: var Turn; bootProc: TurnAction; initialAssertions = initHashSet[Handle]()): Actor =
|
||||
let actor = newActor(name, turn.facet.actor.handleAllocator)
|
||||
enqueue(turn, turn.facet) do (turn: var Turn):
|
||||
var newOutBound: Table[Handle, OutboundAssertion]
|
||||
for key in initialAssertions:
|
||||
discard turn.facet.outbound.pop(key, newOutbound[key])
|
||||
let actor = newActor(name)
|
||||
actor.handleAllocator = turn.facet.actor.handleAllocator
|
||||
when tracing:
|
||||
actor.turnIdAllocator = turn.facet.actor.turnIdAllocator
|
||||
actor.traceStream = turn.facet.actor.traceStream
|
||||
|
@ -474,6 +473,7 @@ proc spawn*(name: string; turn: var Turn; bootProc: TurnAction; initialAssertion
|
|||
act.spawn.id = actor.id.toPreserve
|
||||
turn.desc.actions.add act
|
||||
run(actor, bootProc, newOutBound)
|
||||
actor
|
||||
|
||||
proc newInertRef*(): Ref =
|
||||
let a = bootActor("inert") do (turn: var Turn): turn.stop()
|
||||
|
|
|
@ -14,7 +14,7 @@ type Observe = dataspace.Observe[Ref]
|
|||
|
||||
proc now: float64 = getTime().toUnixFloat()
|
||||
|
||||
proc spawnTimers*(turn: var Turn; ds: Ref) =
|
||||
proc spawnTimers*(turn: var Turn; ds: Ref): Actor {.discardable.} =
|
||||
## Spawn a timer actor.
|
||||
spawn("timer", turn) do (turn: var Turn):
|
||||
|
||||
|
|
|
@ -265,7 +265,7 @@ proc newRelay(turn: var Turn; opts: RelayOptions; setup: RelaySetup): Relay =
|
|||
|
||||
proc spawnRelay*(name: string; turn: var Turn; opts: RelayActorOptions; setup: RelaySetup): Future[Ref] =
|
||||
var fut = newFuture[Ref]"spawnRelay"
|
||||
spawn(name, turn) do (turn: var Turn):
|
||||
discard spawn(name, turn) do (turn: var Turn):
|
||||
let relay = newRelay(turn, opts, setup)
|
||||
if not opts.initialRef.isNil:
|
||||
var exported: seq[WireSymbol]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Package
|
||||
|
||||
version = "20230721"
|
||||
version = "20230722"
|
||||
author = "Emery Hemingway"
|
||||
description = "Syndicated actors for conversational concurrency"
|
||||
license = "Unlicense"
|
||||
|
@ -9,4 +9,4 @@ srcDir = "src"
|
|||
|
||||
# Dependencies
|
||||
|
||||
requires "hashlib", "nim >= 1.4.8", "preserves >= 20230530", "taps >= 20221119"
|
||||
requires "hashlib", "nim >= 1.4.8", "preserves >= 20230720", "taps >= 20221119"
|
||||
|
|
Loading…
Reference in New Issue