2021-04-21 19:22:30 +00:00
|
|
|
import { $BoxState, fromSetBox, SetBox } from "../gen/box-protocol.js";
|
|
|
|
import { fromObserve, Observe } from "../gen/dataspace.js";
|
|
|
|
import { Assertion, Ref, Turn } from "../runtime/actor.js";
|
2021-03-02 08:50:23 +00:00
|
|
|
|
|
|
|
export default function (t: Turn, ds: Ref) {
|
2021-03-03 15:22:19 +00:00
|
|
|
console.log('Spawning Client');
|
|
|
|
let count = 0;
|
2021-03-23 18:18:26 +00:00
|
|
|
t.assert(ds, fromObserve(Observe({
|
|
|
|
label: $BoxState,
|
|
|
|
observer: t.ref({
|
|
|
|
assert(t: Turn, [currentValue]: [number]): void {
|
|
|
|
// console.log(`Client ${t.actor.id}: got ${currentValue}`);
|
|
|
|
t.message(ds, fromSetBox(SetBox(currentValue + 1)));
|
2021-03-02 08:50:23 +00:00
|
|
|
}
|
2021-03-23 18:18:26 +00:00
|
|
|
})
|
|
|
|
})));
|
|
|
|
t.assert(ds, fromObserve(Observe({
|
|
|
|
label: $BoxState,
|
|
|
|
observer: t.ref({
|
|
|
|
assert(_t: Turn, _assertion: Assertion): void {
|
|
|
|
count++;
|
|
|
|
// console.log('inc to', count, _assertion);
|
|
|
|
},
|
|
|
|
retract(t: Turn) {
|
|
|
|
if (--count === 0) {
|
2021-04-16 18:29:16 +00:00
|
|
|
console.log(`Client ${t.activeFacet.id}: detected box termination`);
|
|
|
|
t.stopActor();
|
2021-03-23 18:18:26 +00:00
|
|
|
}
|
|
|
|
// console.log('dec to', count);
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})));
|
2021-03-02 08:50:23 +00:00
|
|
|
}
|