30 lines
840 B
Nim
30 lines
840 B
Nim
# SPDX-License-Identifier: ISC
|
|
|
|
import syndicate/[assertions, macros]
|
|
import preserves, preserves/records
|
|
import asyncdispatch
|
|
|
|
const
|
|
BoxState = RecordClass(label: symbol"box-state", arity: 1)
|
|
SetBox = RecordClass(label: symbol"set-box", arity: 1)
|
|
|
|
syndicate "test_dsl":
|
|
|
|
spawn "box":
|
|
field(currentValue, int, 0)
|
|
assert(BoxState, currentValue)
|
|
stopIf currentValue.get == 10:
|
|
echo "box: terminating"
|
|
onMessage(SetBox) do (newValue: int):
|
|
echo "box: taking on new value ", newValue
|
|
currentValue.set(newValue)
|
|
|
|
spawn "client":
|
|
#stopIf retracted(observe(SetBox, _)):
|
|
# echo "client: box has gone"
|
|
onAsserted(BoxState) do (v: int):
|
|
echo "client: learned that box's value is now ", v
|
|
send(SetBox, v+1)
|
|
onRetracted(BoxState) do (_):
|
|
echo "client: box state disappeared"
|