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,
|
export Actor, Assertion, Facet, Handle, Ref, Symbol, Turn, TurnAction,
|
||||||
`$`, addCallback, analyse, asyncCheck, bootDataspace,
|
`$`, addCallback, analyse, asyncCheck, bootDataspace,
|
||||||
facet, future, inFacet, message, newDataspace, onStop, publish,
|
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.} =
|
proc `!`*(typ: static typedesc): Pattern {.inline.} =
|
||||||
patterns.dropType(typ)
|
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 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
|
let
|
||||||
now = getTime()
|
now = getTime()
|
||||||
seed = now.toUnix * 1_000_000_000 + now.nanosecond
|
seed = now.toUnix * 1_000_000_000 + now.nanosecond
|
||||||
result = Actor(
|
result = Actor(
|
||||||
name: name,
|
name: name,
|
||||||
id: ActorId(seed))
|
id: ActorId(seed),
|
||||||
new result.handleAllocator
|
handleAllocator: handleAlloc,
|
||||||
|
)
|
||||||
result.root = newFacet(result, nil)
|
result.root = newFacet(result, nil)
|
||||||
result.future = newFuture[void]($result)
|
result.future = newFuture[void]($result)
|
||||||
when tracing:
|
when tracing:
|
||||||
|
@ -449,8 +450,7 @@ proc run(actor; bootProc: TurnAction; initialAssertions: OutboundTable) =
|
||||||
|
|
||||||
proc bootActor*(name: string; bootProc: TurnAction): Actor =
|
proc bootActor*(name: string; bootProc: TurnAction): Actor =
|
||||||
var initialAssertions: OutboundTable
|
var initialAssertions: OutboundTable
|
||||||
result = newActor(name)
|
result = newActor(name, new(ref Handle))
|
||||||
new result.handleAllocator
|
|
||||||
when tracing:
|
when tracing:
|
||||||
new result.turnIdAllocator
|
new result.turnIdAllocator
|
||||||
let path = getEnv("SYNDICATE_TRACE_FILE", "/tmp/" & name & ".trace.pr")
|
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)
|
else: result.traceStream = openFileStream(path, fmWrite)
|
||||||
run(result, bootProc, initialAssertions)
|
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):
|
enqueue(turn, turn.facet) do (turn: var Turn):
|
||||||
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])
|
||||||
let actor = newActor(name)
|
|
||||||
actor.handleAllocator = turn.facet.actor.handleAllocator
|
|
||||||
when tracing:
|
when tracing:
|
||||||
actor.turnIdAllocator = turn.facet.actor.turnIdAllocator
|
actor.turnIdAllocator = turn.facet.actor.turnIdAllocator
|
||||||
actor.traceStream = turn.facet.actor.traceStream
|
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
|
act.spawn.id = actor.id.toPreserve
|
||||||
turn.desc.actions.add act
|
turn.desc.actions.add act
|
||||||
run(actor, bootProc, newOutBound)
|
run(actor, bootProc, newOutBound)
|
||||||
|
actor
|
||||||
|
|
||||||
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()
|
||||||
|
|
|
@ -14,7 +14,7 @@ type Observe = dataspace.Observe[Ref]
|
||||||
|
|
||||||
proc now: float64 = getTime().toUnixFloat()
|
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 a timer actor.
|
||||||
spawn("timer", turn) do (turn: var Turn):
|
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] =
|
proc spawnRelay*(name: string; turn: var Turn; opts: RelayActorOptions; setup: RelaySetup): Future[Ref] =
|
||||||
var fut = newFuture[Ref]"spawnRelay"
|
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)
|
let relay = newRelay(turn, opts, setup)
|
||||||
if not opts.initialRef.isNil:
|
if not opts.initialRef.isNil:
|
||||||
var exported: seq[WireSymbol]
|
var exported: seq[WireSymbol]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "20230721"
|
version = "20230722"
|
||||||
author = "Emery Hemingway"
|
author = "Emery Hemingway"
|
||||||
description = "Syndicated actors for conversational concurrency"
|
description = "Syndicated actors for conversational concurrency"
|
||||||
license = "Unlicense"
|
license = "Unlicense"
|
||||||
|
@ -9,4 +9,4 @@ srcDir = "src"
|
||||||
|
|
||||||
# Dependencies
|
# 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