2021-04-24 22:15:15 +00:00
|
|
|
import { Actor, Assertion, Turn } from '../runtime/actor.js';
|
|
|
|
import { Dictionary, embed } from '@preserves/core';
|
2021-04-21 19:22:30 +00:00
|
|
|
import { Dataspace } from '../runtime/dataspace.js';
|
2021-05-17 13:13:55 +00:00
|
|
|
import { _embedded, attenuate, CRec, Lit, Pattern, PCompound, rfilter, ConstructorSpec } from '../runtime/rewrite.js';
|
2021-04-21 19:22:30 +00:00
|
|
|
import { $BoxState, $SetBox } from '../gen/box-protocol.js';
|
|
|
|
import { $Observe } from '../gen/dataspace.js';
|
|
|
|
import { spawnWorker } from '../worker/index.js';
|
2021-03-02 12:53:33 +00:00
|
|
|
import path from 'path';
|
2021-02-23 15:16:15 +00:00
|
|
|
|
2021-03-02 08:50:23 +00:00
|
|
|
function spawnModule(t: Turn, moduleName: string, arg: Assertion) {
|
2021-03-03 15:23:00 +00:00
|
|
|
import(moduleName).then(m => t.freshen(t => t.spawn(t => m.default(t, arg))));
|
2021-02-23 15:16:15 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 11:41:06 +00:00
|
|
|
// __setNextActorId(1000);
|
|
|
|
|
2021-04-16 18:29:16 +00:00
|
|
|
new Actor(async (t: Turn) => {
|
2021-03-03 10:45:01 +00:00
|
|
|
const ds_unproxied = t.ref(new Dataspace());
|
|
|
|
|
|
|
|
const ds = ds_unproxied;
|
|
|
|
// const { proxy: ds, revoker } = forwarder(t, ds_unproxied);
|
|
|
|
// t.spawn(t => {
|
|
|
|
// t.assert(ds, Observe(SetBox.constructorInfo.label, t.ref({
|
|
|
|
// message(t: Turn, [newValue]: [number]): void {
|
|
|
|
// if (newValue === 30000) {
|
|
|
|
// console.log('BOOM!');
|
|
|
|
// t.message(revoker, true);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// })));
|
|
|
|
// });
|
2021-02-24 20:48:55 +00:00
|
|
|
|
2021-03-02 11:41:06 +00:00
|
|
|
const ds_for_box = attenuate(
|
|
|
|
ds,
|
2021-03-23 11:18:57 +00:00
|
|
|
rfilter(
|
2021-03-23 18:18:26 +00:00
|
|
|
Pattern.PCompound(PCompound({
|
|
|
|
ctor: ConstructorSpec.CRec(CRec({ label: $BoxState, arity: 1 })),
|
|
|
|
members: new Dictionary()
|
|
|
|
})),
|
|
|
|
Pattern.PCompound(PCompound({
|
|
|
|
ctor: ConstructorSpec.CRec(CRec({ label: $Observe, arity: 2 })),
|
2021-05-17 13:13:55 +00:00
|
|
|
members: new Dictionary<_embedded, Pattern>([
|
2021-03-23 18:18:26 +00:00
|
|
|
[0, Pattern.Lit(Lit($SetBox))]])
|
|
|
|
}))));
|
2021-03-02 11:41:06 +00:00
|
|
|
|
|
|
|
const ds_for_client = attenuate(
|
2021-03-03 10:45:01 +00:00
|
|
|
ds_unproxied,
|
2021-03-23 11:18:57 +00:00
|
|
|
rfilter(
|
2021-03-23 18:18:26 +00:00
|
|
|
Pattern.PCompound(PCompound({
|
|
|
|
ctor: ConstructorSpec.CRec(CRec({ label: $SetBox, arity: 1 })),
|
|
|
|
members: new Dictionary()
|
|
|
|
})),
|
|
|
|
Pattern.PCompound(PCompound({
|
|
|
|
ctor: ConstructorSpec.CRec(CRec({ label: $Observe, arity: 2 })),
|
2021-05-17 13:13:55 +00:00
|
|
|
members: new Dictionary<_embedded, Pattern>([
|
2021-03-23 18:18:26 +00:00
|
|
|
[0, Pattern.Lit(Lit($BoxState))]])
|
|
|
|
}))));
|
2021-03-02 11:41:06 +00:00
|
|
|
|
2021-03-02 12:53:33 +00:00
|
|
|
const boxpath = path.join(__dirname, 'box.js');
|
|
|
|
const clientpath = path.join(__dirname, 'client.js');
|
2021-03-02 11:41:06 +00:00
|
|
|
|
2021-05-31 10:02:46 +00:00
|
|
|
t.activeFacet.preventInertCheck();
|
|
|
|
|
2021-04-24 22:15:15 +00:00
|
|
|
// spawnModule(t, boxpath, [embed(ds_for_box), 500000, 25000]);
|
|
|
|
spawnWorker(t, boxpath, [embed(ds_for_box), 50000, 2500]);
|
2021-02-24 20:48:55 +00:00
|
|
|
|
2021-04-24 22:15:15 +00:00
|
|
|
spawnModule(t, clientpath, embed(ds_for_client));
|
|
|
|
// spawnWorker(t, clientpath, embed(ds_for_client));
|
2021-02-22 09:12:10 +00:00
|
|
|
});
|