26 lines
944 B
TypeScript
26 lines
944 B
TypeScript
import { BoxState, SetBox } from "./box-protocol.js";
|
|
import { Observe } from "./dataspace.js";
|
|
import { Assertion, Handle, Ref, Turn } from "./actor.js";
|
|
|
|
export default function (t: Turn, ds: Ref) {
|
|
t.spawn(t => {
|
|
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: got ${currentValue}`);
|
|
t.message(ds, SetBox(currentValue + 1));
|
|
}
|
|
})));
|
|
t.assert(ds, Observe(BoxState.constructorInfo.label, t.ref({
|
|
assert(_t: Turn, _assertion: Assertion): void { count++; },
|
|
retract(t: Turn, _handle: Handle) {
|
|
if (--count === 0) {
|
|
console.log('Client: detected box termination');
|
|
t.quit();
|
|
}
|
|
},
|
|
})));
|
|
});
|
|
}
|