2021-03-11 17:00:45 +00:00
|
|
|
import { BoxState, SetBox } from "./gen/box-protocol.js";
|
2021-03-11 20:56:35 +00:00
|
|
|
import { Observe } from "./gen/dataspace.js";
|
2021-03-03 10:45:01 +00:00
|
|
|
import { Assertion, Ref, Turn } from "./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;
|
|
|
|
t.assert(ds, Observe(BoxState.constructorInfo.label, t.ref({
|
|
|
|
assert(t: Turn, [currentValue]: [number]): void {
|
|
|
|
// console.log(`Client ${t.actor.id}: got ${currentValue}`);
|
|
|
|
t.message(ds, SetBox(currentValue + 1));
|
|
|
|
}
|
|
|
|
})));
|
|
|
|
t.assert(ds, Observe(BoxState.constructorInfo.label, t.ref({
|
|
|
|
assert(_t: Turn, _assertion: Assertion): void {
|
|
|
|
count++;
|
|
|
|
// console.log('inc to', count, _assertion);
|
|
|
|
},
|
|
|
|
retract(t: Turn) {
|
|
|
|
if (--count === 0) {
|
|
|
|
console.log(`Client ${t.actor.id}: detected box termination`);
|
|
|
|
t.quit();
|
2021-03-02 08:50:23 +00:00
|
|
|
}
|
2021-03-03 15:22:19 +00:00
|
|
|
// console.log('dec to', count);
|
|
|
|
},
|
|
|
|
})));
|
2021-03-02 08:50:23 +00:00
|
|
|
}
|