Attenuation with relaying - not finished yet
This commit is contained in:
parent
096262fdd5
commit
f29a7946f2
3
actor.ts
3
actor.ts
|
@ -101,6 +101,9 @@ export function isRef(v: any): v is Ref {
|
||||||
}
|
}
|
||||||
|
|
||||||
let nextActorId = 0;
|
let nextActorId = 0;
|
||||||
|
// export function __setNextActorId(v: number) {
|
||||||
|
// nextActorId = v;
|
||||||
|
// }
|
||||||
|
|
||||||
export class Actor {
|
export class Actor {
|
||||||
readonly id = nextActorId++;
|
readonly id = nextActorId++;
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
import { Ref } from "actor";
|
import { Ref } from "actor";
|
||||||
import { Record } from "preserves";
|
import { Record } from "preserves";
|
||||||
|
|
||||||
|
export const _BoxState = Symbol.for('BoxState');
|
||||||
export const BoxState = Record.makeConstructor<{value: number}, Ref>()(
|
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>()(
|
export const SetBox = Record.makeConstructor<{newValue: number}, Ref>()(
|
||||||
Symbol.for('SetBox'), ['newValue']);
|
_SetBox, ['newValue']);
|
||||||
|
|
53
main.ts
53
main.ts
|
@ -1,8 +1,9 @@
|
||||||
import { Actor, Assertion, Turn } from './actor.js';
|
import { Actor, Assertion, attenuate, CRec, Lit, Pattern, PCompound, Ref, rfilter, Turn } from './actor.js';
|
||||||
import { Record } from 'preserves';
|
import { Dictionary, Record } from 'preserves';
|
||||||
import { Dataspace } from './dataspace.js';
|
import { Dataspace, Observe } from './dataspace.js';
|
||||||
import { Worker } from 'worker_threads';
|
import { Worker } from 'worker_threads';
|
||||||
import { Relay, spawnRelay } from './relay.js';
|
import { Relay, spawnRelay } from './relay.js';
|
||||||
|
import { BoxState, SetBox } from './box-protocol.js';
|
||||||
|
|
||||||
const Instance = Record.makeConstructor<{moduleName: string, arg: Assertion}>()(
|
const Instance = Record.makeConstructor<{moduleName: string, arg: Assertion}>()(
|
||||||
Symbol.for('Instance'), ['moduleName', 'arg']);
|
Symbol.for('Instance'), ['moduleName', 'arg']);
|
||||||
|
@ -33,31 +34,37 @@ function spawnModule(t: Turn, moduleName: string, arg: Assertion) {
|
||||||
m.default(t, arg))));
|
m.default(t, arg))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// __setNextActorId(1000);
|
||||||
|
|
||||||
Turn.for(new Actor(), async (t: Turn) => {
|
Turn.for(new Actor(), async (t: Turn) => {
|
||||||
const ds = t.ref(new Dataspace());
|
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]);
|
// 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);
|
// spawnModule(t, './client.js', ds_for_client);
|
||||||
// spawnWorker(t, './client.js', ds);
|
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)]])))));
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue