2021-06-24 15:50:27 +00:00
|
|
|
# SPDX-License-Identifier: ISC
|
|
|
|
|
2021-06-27 10:38:04 +00:00
|
|
|
import syndicate/assertions, syndicate/dataspaces, syndicate/events, syndicate/skeletons
|
|
|
|
import preserves, preserves/records
|
2021-06-24 15:50:27 +00:00
|
|
|
import asyncdispatch, tables, options
|
|
|
|
|
2021-08-28 08:36:30 +00:00
|
|
|
import ./box_and_client
|
|
|
|
|
2021-06-24 15:50:27 +00:00
|
|
|
const N = 100000
|
|
|
|
|
|
|
|
const
|
2021-07-08 09:50:13 +00:00
|
|
|
`?_` = init(Discard)
|
|
|
|
`?$` = init(Capture, `?_`)
|
2021-06-24 15:50:27 +00:00
|
|
|
|
|
|
|
proc boot(facet: Facet) =
|
|
|
|
|
|
|
|
facet.spawn("box") do (facet: Facet):
|
|
|
|
facet.declareField(value, int, 0)
|
|
|
|
|
2021-07-09 10:38:10 +00:00
|
|
|
facet.addEndpoint do (facet: Facet) -> EndpointSpec:
|
2021-06-24 15:50:27 +00:00
|
|
|
# echo "recomputing published BoxState ", facet.fields.value
|
2021-08-28 08:36:30 +00:00
|
|
|
result.assertion = prsBoxState(value.getPreserve)
|
2021-06-24 15:50:27 +00:00
|
|
|
|
2021-07-09 10:38:10 +00:00
|
|
|
facet.addDataflow do (facet: Facet):
|
2021-06-24 15:50:27 +00:00
|
|
|
# echo "box dataflow saw new value ", facet.fields.value
|
2021-06-29 15:18:09 +00:00
|
|
|
if value.get == N:
|
2021-06-24 15:50:27 +00:00
|
|
|
facet.stop do (facet: Facet):
|
|
|
|
echo "terminated box root facet"
|
|
|
|
|
2021-07-09 10:38:10 +00:00
|
|
|
facet.addEndpoint do (facet: Facet) -> EndpointSpec:
|
2021-08-28 08:36:30 +00:00
|
|
|
const a = prsSetBox(`?$`)
|
2021-07-08 09:50:13 +00:00
|
|
|
result.analysis = some analyzeAssertion(a)
|
|
|
|
proc cb(facet: Facet; vs: seq[Value]) =
|
|
|
|
facet.scheduleScript do (facet: Facet):
|
|
|
|
value.set(vs[0])
|
|
|
|
# echo "box updated value ", vs[0]
|
2021-07-09 10:38:10 +00:00
|
|
|
result.callback = facet.wrap(messageEvent, cb)
|
2021-08-28 08:36:30 +00:00
|
|
|
result.assertion = Observe.init(prsSetBox(`?$`))
|
2021-06-24 15:50:27 +00:00
|
|
|
|
|
|
|
facet.spawn("client") do (facet: Facet):
|
|
|
|
|
2021-07-09 10:38:10 +00:00
|
|
|
facet.addEndpoint do (facet: Facet) -> EndpointSpec:
|
2021-08-28 08:36:30 +00:00
|
|
|
const a = prsBoxState(`?$`)
|
2021-07-08 09:50:13 +00:00
|
|
|
result.analysis = some analyzeAssertion(a)
|
|
|
|
proc cb(facet: Facet; vs: seq[Value]) =
|
|
|
|
facet.scheduleScript do (facet: Facet):
|
2021-08-28 08:36:30 +00:00
|
|
|
let v = prsSetBox(vs[0].int.succ.toPreserve)
|
2021-07-08 09:50:13 +00:00
|
|
|
# echo "client sending ", v
|
|
|
|
facet.send(v)
|
2021-07-09 10:38:10 +00:00
|
|
|
result.callback = facet.wrap(addedEvent, cb)
|
2021-08-28 08:36:30 +00:00
|
|
|
result.assertion = Observe.init(prsBoxState(`?$`))
|
2021-06-24 15:50:27 +00:00
|
|
|
|
2021-07-09 10:38:10 +00:00
|
|
|
facet.addEndpoint do (facet: Facet) -> EndpointSpec:
|
2021-08-28 08:36:30 +00:00
|
|
|
const a = prsBoxState(`?_`)
|
2021-07-08 09:50:13 +00:00
|
|
|
result.analysis = some analyzeAssertion(a)
|
|
|
|
proc cb(facet: Facet; vs: seq[Value]) =
|
|
|
|
facet.scheduleScript do (facet: Facet):
|
|
|
|
echo "box gone"
|
2021-07-09 10:38:10 +00:00
|
|
|
result.callback = facet.wrap(removedEvent, cb)
|
2021-08-28 08:36:30 +00:00
|
|
|
result.assertion = Observe.init(prsBoxState(`?_`))
|
2021-06-24 15:50:27 +00:00
|
|
|
|
|
|
|
facet.actor.dataspace.ground.addStopHandler do (_: Dataspace):
|
|
|
|
echo "stopping box-and-client"
|
|
|
|
|
2021-06-29 14:31:08 +00:00
|
|
|
waitFor bootModule("box-and-client", boot)
|