Move durings into new facets
This commit is contained in:
parent
d654195fb8
commit
bf8f7e9aaa
|
@ -173,8 +173,7 @@ macro during*(turn: untyped; ds: Cap; pattern: Pattern; publishBody, retractBody
|
||||||
if `argCount` != 0 and `pattern`.analyse.capturePaths.len != `argCount`:
|
if `argCount` != 0 and `pattern`.analyse.capturePaths.len != `argCount`:
|
||||||
raiseAssert($`pattern`.analyse.capturePaths.len & " values captured but handler has " & $`argCount` & " arguments - " & $`pattern`)
|
raiseAssert($`pattern`.analyse.capturePaths.len & " values captured but handler has " & $`argCount` & " arguments - " & $`pattern`)
|
||||||
`callbackProc`
|
`callbackProc`
|
||||||
discard inFacet(`turn`) do (`turn`: var Turn):
|
discard observe(`turn`, `ds`, `pattern`, during(`callbackSym`))
|
||||||
discard observe(`turn`, `ds`, `pattern`, during(`callbackSym`))
|
|
||||||
|
|
||||||
macro during*(turn: untyped; ds: Cap; pattern: Pattern; publishBody: untyped) =
|
macro during*(turn: untyped; ds: Cap; pattern: Pattern; publishBody: untyped) =
|
||||||
## Variant of `during` without a retract body.
|
## Variant of `during` without a retract body.
|
||||||
|
@ -186,5 +185,4 @@ macro during*(turn: untyped; ds: Cap; pattern: Pattern; publishBody: untyped) =
|
||||||
if `argCount` != 0 and `pattern`.analyse.capturePaths.len != `argCount`:
|
if `argCount` != 0 and `pattern`.analyse.capturePaths.len != `argCount`:
|
||||||
raiseAssert($`pattern`.analyse.capturePaths.len & " values captured but handler has " & $`argCount` & " arguments - " & $`pattern`)
|
raiseAssert($`pattern`.analyse.capturePaths.len & " values captured but handler has " & $`argCount` & " arguments - " & $`pattern`)
|
||||||
`callbackProc`
|
`callbackProc`
|
||||||
discard inFacet(`turn`) do (`turn`: var Turn):
|
discard observe(`turn`, `ds`, `pattern`, during(`callbackSym`))
|
||||||
discard observe(`turn`, `ds`, `pattern`, during(`callbackSym`))
|
|
||||||
|
|
|
@ -507,7 +507,7 @@ proc stopIfInertAfter(action: TurnAction): TurnAction =
|
||||||
|
|
||||||
proc newFacet(turn: var Turn): Facet = newFacet(turn.facet.actor, turn.facet)
|
proc newFacet(turn: var Turn): Facet = newFacet(turn.facet.actor, turn.facet)
|
||||||
|
|
||||||
proc inFacet*(turn: var Turn; bootProc: TurnAction): Facet =
|
proc inFacet*(turn: var Turn; bootProc: TurnAction): Facet {.discardable.} =
|
||||||
result = newFacet(turn)
|
result = newFacet(turn)
|
||||||
recallFacet turn:
|
recallFacet turn:
|
||||||
turn.facet = result
|
turn.facet = result
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# SPDX-FileCopyrightText: ☭ 2021 Emery Hemingway
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||||||
# SPDX-License-Identifier: Unlicense
|
# SPDX-License-Identifier: Unlicense
|
||||||
|
|
||||||
import std/[hashes, tables]
|
import std/[hashes, tables]
|
||||||
|
@ -18,17 +18,18 @@ type
|
||||||
assertionMap: Table[Handle, DuringAction]
|
assertionMap: Table[Handle, DuringAction]
|
||||||
|
|
||||||
method publish(de: DuringEntity; turn: var Turn; a: AssertionRef; h: Handle) =
|
method publish(de: DuringEntity; turn: var Turn; a: AssertionRef; h: Handle) =
|
||||||
let action = de.cb(turn, a.value, h)
|
discard inFacet(turn) do (turn: var Turn):
|
||||||
# assert(not action.isNil "should have put in a no-op action")
|
let action = de.cb(turn, a.value, h)
|
||||||
let g = de.assertionMap.getOrDefault h
|
# assert(not action.isNil "should have put in a no-op action")
|
||||||
case g.kind
|
let g = de.assertionMap.getOrDefault h
|
||||||
of null:
|
case g.kind
|
||||||
de.assertionMap[h] = DuringAction(kind: act, action: action)
|
of null:
|
||||||
of dead:
|
de.assertionMap[h] = DuringAction(kind: act, action: action)
|
||||||
de.assertionMap.del h
|
of dead:
|
||||||
freshen(turn, action)
|
de.assertionMap.del h
|
||||||
of act:
|
action(turn)
|
||||||
raiseAssert("during: duplicate handle in publish: " & $h)
|
of act:
|
||||||
|
raiseAssert("during: duplicate handle in publish: " & $h)
|
||||||
|
|
||||||
method retract(de: DuringEntity; turn: var Turn; h: Handle) =
|
method retract(de: DuringEntity; turn: var Turn; h: Handle) =
|
||||||
let g = de.assertionMap.getOrDefault h
|
let g = de.assertionMap.getOrDefault h
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "20240315"
|
version = "20240319"
|
||||||
author = "Emery Hemingway"
|
author = "Emery Hemingway"
|
||||||
description = "Syndicated actors for conversational concurrency"
|
description = "Syndicated actors for conversational concurrency"
|
||||||
license = "Unlicense"
|
license = "Unlicense"
|
||||||
|
|
Loading…
Reference in New Issue