Get raw box-and-client example running again
This commit is contained in:
parent
2223f29ad2
commit
3042a23aad
|
@ -21,70 +21,81 @@ const Immutable = require('immutable');
|
||||||
const Syndicate = require('../src/index.js');
|
const Syndicate = require('../src/index.js');
|
||||||
const Skeleton = Syndicate.Skeleton;
|
const Skeleton = Syndicate.Skeleton;
|
||||||
const Dataspace = Syndicate.Dataspace;
|
const Dataspace = Syndicate.Dataspace;
|
||||||
const Ground = Syndicate.Ground.Ground;
|
const Ground = Syndicate.Ground;
|
||||||
const Struct = Syndicate.Struct;
|
const Record = Syndicate.Record;
|
||||||
const __ = Syndicate.__;
|
const __ = Syndicate.Discard._instance;
|
||||||
const _$ = Syndicate._$;
|
const _$ = Syndicate.Capture(__);
|
||||||
|
|
||||||
const BoxState = Struct.makeConstructor('BoxState', ['value']);
|
const BoxState = Record.makeConstructor('BoxState', ['value']);
|
||||||
const SetBox = Struct.makeConstructor('SetBox', ['newValue']);
|
const SetBox = Record.makeConstructor('SetBox', ['newValue']);
|
||||||
|
|
||||||
const N = 100000;
|
const N = 100000;
|
||||||
|
|
||||||
console.time('box-and-client-' + N.toString());
|
console.time('box-and-client-' + N.toString());
|
||||||
|
let _savedGlobalFacet = Dataspace._currentFacet;
|
||||||
|
Dataspace._currentFacet = new Syndicate._Dataspace.ActionCollector();
|
||||||
|
|
||||||
new Ground(() => {
|
Dataspace.spawn('box', function () {
|
||||||
Dataspace.spawn('box', function () {
|
Dataspace.declareField(this, 'value', 0);
|
||||||
Dataspace.declareField(this, 'value', 0);
|
Dataspace.currentFacet().addEndpoint(() => {
|
||||||
Dataspace.currentFacet().addEndpoint(() => {
|
return [BoxState(this.value), null];
|
||||||
return [BoxState(this.value), null];
|
});
|
||||||
});
|
Dataspace.currentFacet().addDataflow(() => {
|
||||||
Dataspace.currentFacet().addDataflow(() => {
|
if (this.value === N) {
|
||||||
if (this.value === N) {
|
Dataspace.currentFacet().stop(() => {
|
||||||
Dataspace.currentFacet().stop(() => {
|
console.log('terminated box root facet');
|
||||||
console.log('terminated box root facet');
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Dataspace.currentFacet().addEndpoint(() => {
|
||||||
|
let handler = Skeleton.analyzeAssertion(SetBox(_$));
|
||||||
|
handler.callback = Dataspace.wrap((evt, vs) => {
|
||||||
|
if (evt === Skeleton.EVENT_MESSAGE) {
|
||||||
|
Dataspace.currentFacet().actor.scheduleScript(() => {
|
||||||
|
this.value = vs.get(0);
|
||||||
|
// console.log('box updated value', vs.get(0));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Dataspace.currentFacet().addEndpoint(() => {
|
return [Syndicate.Observe(SetBox(_$)), handler];
|
||||||
let handler = Skeleton.analyzeAssertion(SetBox(_$));
|
});
|
||||||
handler.callback = Dataspace.wrap((evt, vs) => {
|
});
|
||||||
if (evt === Skeleton.EVENT_MESSAGE) {
|
|
||||||
Dataspace.currentFacet().actor.scheduleScript(() => {
|
Dataspace.spawn('client', () => {
|
||||||
this.value = vs.get(0);
|
Dataspace.currentFacet().addEndpoint(() => {
|
||||||
// console.log('box updated value', vs.get(0));
|
let handler = Skeleton.analyzeAssertion(BoxState(_$));
|
||||||
});
|
handler.callback = Dataspace.wrap((evt, vs) => {
|
||||||
}
|
if (evt === Skeleton.EVENT_ADDED) {
|
||||||
});
|
Dataspace.currentFacet().actor.scheduleScript(() => {
|
||||||
return [Syndicate.Observe(SetBox(_$)), handler];
|
// console.log('client sending SetBox', vs.get(0) + 1);
|
||||||
});
|
Dataspace.send(SetBox(vs.get(0) + 1));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return [Syndicate.Observe(BoxState(_$)), handler];
|
||||||
|
});
|
||||||
|
Dataspace.currentFacet().addEndpoint(() => {
|
||||||
|
let handler = Skeleton.analyzeAssertion(BoxState(__));
|
||||||
|
handler.callback = Dataspace.wrap((evt, vs) => {
|
||||||
|
if (evt === Skeleton.EVENT_REMOVED) {
|
||||||
|
Dataspace.currentFacet().actor.scheduleScript(() => {
|
||||||
|
console.log('box gone');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return [Syndicate.Observe(BoxState(__)), handler];
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports[Dataspace.BootSteps] = {
|
||||||
|
module: module,
|
||||||
|
steps: Dataspace._currentFacet.actions
|
||||||
|
};
|
||||||
|
Dataspace._currentFacet = _savedGlobalFacet;
|
||||||
|
_savedGlobalFacet = null;
|
||||||
|
|
||||||
|
Ground.bootModule(module, (g) => {
|
||||||
|
g.addStopHandler(() => {
|
||||||
|
console.timeEnd('box-and-client-' + N.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
Dataspace.spawn('client', () => {
|
|
||||||
Dataspace.currentFacet().addEndpoint(() => {
|
|
||||||
let handler = Skeleton.analyzeAssertion(BoxState(_$));
|
|
||||||
handler.callback = Dataspace.wrap((evt, vs) => {
|
|
||||||
if (evt === Skeleton.EVENT_ADDED) {
|
|
||||||
Dataspace.currentFacet().actor.scheduleScript(() => {
|
|
||||||
// console.log('client sending SetBox', vs.get(0) + 1);
|
|
||||||
Dataspace.send(SetBox(vs.get(0) + 1));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return [Syndicate.Observe(BoxState(_$)), handler];
|
|
||||||
});
|
|
||||||
Dataspace.currentFacet().addEndpoint(() => {
|
|
||||||
let handler = Skeleton.analyzeAssertion(BoxState(__));
|
|
||||||
handler.callback = Dataspace.wrap((evt, vs) => {
|
|
||||||
if (evt === Skeleton.EVENT_REMOVED) {
|
|
||||||
Dataspace.currentFacet().actor.scheduleScript(() => {
|
|
||||||
console.log('box gone');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return [Syndicate.Observe(BoxState(__)), handler];
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}).start().addStopHandler(() => {
|
|
||||||
console.timeEnd('box-and-client-' + N.toString());
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -88,7 +88,7 @@ Ground.prototype.addStopHandler = function (h) {
|
||||||
this.stopHandlers.push(h);
|
this.stopHandlers.push(h);
|
||||||
};
|
};
|
||||||
|
|
||||||
function bootModule(mod) {
|
function bootModule(mod, k) {
|
||||||
let g = new Ground(() => {
|
let g = new Ground(() => {
|
||||||
Worker.spawnWorkerRelay();
|
Worker.spawnWorkerRelay();
|
||||||
if (Dataspace.BootSteps in mod) {
|
if (Dataspace.BootSteps in mod) {
|
||||||
|
@ -104,7 +104,10 @@ function bootModule(mod) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (typeof document !== 'undefined') {
|
if (typeof document !== 'undefined') {
|
||||||
document.addEventListener("DOMContentLoaded", (e) => { g.start(); });
|
document.addEventListener("DOMContentLoaded", (e) => {
|
||||||
|
g.start();
|
||||||
|
if (k) k(g);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
process.on('SIGQUIT', () => {
|
process.on('SIGQUIT', () => {
|
||||||
console.log('---------------------------------------------------------------------------');
|
console.log('---------------------------------------------------------------------------');
|
||||||
|
@ -119,6 +122,7 @@ function bootModule(mod) {
|
||||||
// sp.stdin.end(g._dotGraph());
|
// sp.stdin.end(g._dotGraph());
|
||||||
});
|
});
|
||||||
g.start();
|
g.start();
|
||||||
|
if (k) k(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue