Attenuation with relaying - not finished yet

This commit is contained in:
Tony Garnock-Jones 2021-03-02 12:41:06 +01:00
parent 096262fdd5
commit f29a7946f2
3 changed files with 38 additions and 25 deletions

View File

@ -101,6 +101,9 @@ export function isRef(v: any): v is Ref {
}
let nextActorId = 0;
// export function __setNextActorId(v: number) {
// nextActorId = v;
// }
export class Actor {
readonly id = nextActorId++;

View File

@ -1,7 +1,10 @@
import { Ref } from "actor";
import { Record } from "preserves";
export const _BoxState = Symbol.for('BoxState');
export const BoxState = Record.makeConstructor<{value: number}, Ref>()(
Symbol.for('BoxState'), ['value']);
_BoxState, ['value']);
export const _SetBox = Symbol.for('SetBox');
export const SetBox = Record.makeConstructor<{newValue: number}, Ref>()(
Symbol.for('SetBox'), ['newValue']);
_SetBox, ['newValue']);

53
main.ts
View File

@ -1,8 +1,9 @@
import { Actor, Assertion, Turn } from './actor.js';
import { Record } from 'preserves';
import { Dataspace } from './dataspace.js';
import { Actor, Assertion, attenuate, CRec, Lit, Pattern, PCompound, Ref, rfilter, Turn } from './actor.js';
import { Dictionary, Record } from 'preserves';
import { Dataspace, Observe } from './dataspace.js';
import { Worker } from 'worker_threads';
import { Relay, spawnRelay } from './relay.js';
import { BoxState, SetBox } from './box-protocol.js';
const Instance = Record.makeConstructor<{moduleName: string, arg: Assertion}>()(
Symbol.for('Instance'), ['moduleName', 'arg']);
@ -33,31 +34,37 @@ function spawnModule(t: Turn, moduleName: string, arg: Assertion) {
m.default(t, arg))));
}
// __setNextActorId(1000);
Turn.for(new Actor(), async (t: Turn) => {
const ds = t.ref(new Dataspace());
const ds_for_box = attenuate(
ds,
rfilter(PCompound(CRec(BoxState.constructorInfo.label,
BoxState.constructorInfo.arity),
new Dictionary()),
PCompound(CRec(Observe.constructorInfo.label,
Observe.constructorInfo.arity),
new Dictionary<Pattern, Ref>([
[0, Lit(SetBox.constructorInfo.label)]]))));
const ds_for_client = attenuate(
ds,
rfilter(PCompound(CRec(SetBox.constructorInfo.label,
SetBox.constructorInfo.arity),
new Dictionary()),
PCompound(CRec(Observe.constructorInfo.label,
Observe.constructorInfo.arity),
new Dictionary<Pattern, Ref>([
[0, Lit(BoxState.constructorInfo.label)]]))));
// spawnModule(t, './box.js', [ds, 500000, 25000]);
spawnWorker(t, './box.js', [ds, 50000, 2500]);
spawnWorker(t, './box.js', [ds_for_box, 50000, 2500]);
spawnModule(t, './client.js', ds);
// spawnWorker(t, './client.js', ds);
// spawnModule(t, './client.js', ds_for_client);
spawnWorker(t, './client.js', ds_for_client);
// spawnBox(t, attenuate(
// ds,
// rfilter(PCompound(CRec(BoxState.constructorInfo.label,
// BoxState.constructorInfo.arity),
// new Dictionary()),
// PCompound(CRec(Observe.constructorInfo.label,
// Observe.constructorInfo.arity),
// new Dictionary([[0, Lit(SetBox.constructorInfo.label)]])))));
// spawnClient(t, attenuate(
// ds,
// rfilter(PCompound(CRec(SetBox.constructorInfo.label,
// SetBox.constructorInfo.arity),
// new Dictionary()),
// PCompound(CRec(Observe.constructorInfo.label,
// Observe.constructorInfo.arity),
// new Dictionary([[0, Lit(BoxState.constructorInfo.label)]])))));
});