Approach new syntax
This commit is contained in:
parent
b60551a52b
commit
595a13dfd6
|
@ -28,26 +28,26 @@ const N = 100000;
|
|||
|
||||
console.time('box-and-client-' + N.toString());
|
||||
|
||||
new Ground(groundRoot => {
|
||||
groundRoot.spawn('box', function (boxRoot) {
|
||||
boxRoot.actor.dataspace.declareField(this, 'value', 0);
|
||||
boxRoot.addEndpoint(() => {
|
||||
export function boot(thisFacet) {
|
||||
thisFacet.spawn('box', function (thisFacet) {
|
||||
thisFacet.actor.dataspace.declareField(this, 'value', 0);
|
||||
thisFacet.addEndpoint(() => {
|
||||
// console.log('recomputing published BoxState', this.value);
|
||||
return { assertion: BoxState(this.value), analysis: null };
|
||||
});
|
||||
boxRoot.addDataflow(() => {
|
||||
thisFacet.addDataflow(() => {
|
||||
// console.log('dataflow saw new value', this.value);
|
||||
if (this.value === N) {
|
||||
boxRoot.stop(() => {
|
||||
thisFacet.stop(() => {
|
||||
console.log('terminated box root facet');
|
||||
});
|
||||
}
|
||||
});
|
||||
boxRoot.addEndpoint(() => {
|
||||
thisFacet.addEndpoint(() => {
|
||||
let analysis = Skeleton.analyzeAssertion(SetBox(_$));
|
||||
analysis.callback = boxRoot.wrap((facet, evt, vs) => {
|
||||
analysis.callback = thisFacet.wrap((thisFacet, evt, vs) => {
|
||||
if (evt === Skeleton.EventType.MESSAGE) {
|
||||
boxRoot.scheduleScript(() => {
|
||||
thisFacet.scheduleScript(() => {
|
||||
this.value = vs[0];
|
||||
// console.log('box updated value', vs[0]);
|
||||
});
|
||||
|
@ -57,24 +57,24 @@ new Ground(groundRoot => {
|
|||
});
|
||||
});
|
||||
|
||||
groundRoot.spawn('client', function (clientRoot) {
|
||||
clientRoot.addEndpoint(() => {
|
||||
thisFacet.spawn('client', function (thisFacet) {
|
||||
thisFacet.addEndpoint(() => {
|
||||
let analysis = Skeleton.analyzeAssertion(BoxState(_$));
|
||||
analysis.callback = clientRoot.wrap((facet, evt, vs) => {
|
||||
analysis.callback = thisFacet.wrap((thisFacet, evt, vs) => {
|
||||
if (evt === Skeleton.EventType.ADDED) {
|
||||
clientRoot.scheduleScript(() => {
|
||||
thisFacet.scheduleScript(() => {
|
||||
// console.log('client sending SetBox', vs[0] + 1);
|
||||
clientRoot.send(SetBox(vs[0] + 1));
|
||||
thisFacet.send(SetBox(vs[0] + 1));
|
||||
});
|
||||
}
|
||||
});
|
||||
return { assertion: Observe(BoxState(_$)), analysis };
|
||||
});
|
||||
clientRoot.addEndpoint(() => {
|
||||
thisFacet.addEndpoint(() => {
|
||||
let analysis = Skeleton.analyzeAssertion(BoxState(__));
|
||||
analysis.callback = clientRoot.wrap((facet, evt, _vs) => {
|
||||
analysis.callback = thisFacet.wrap((thisFacet, evt, _vs) => {
|
||||
if (evt === Skeleton.EventType.REMOVED) {
|
||||
clientRoot.scheduleScript(() => {
|
||||
thisFacet.scheduleScript(() => {
|
||||
console.log('box gone');
|
||||
});
|
||||
}
|
||||
|
@ -82,4 +82,9 @@ new Ground(groundRoot => {
|
|||
return { assertion: Observe(BoxState(__)), analysis };
|
||||
});
|
||||
});
|
||||
}).addStopHandler(() => console.timeEnd('box-and-client-' + N.toString())).start();
|
||||
|
||||
thisFacet.actor.dataspace.addStopHandler(() =>
|
||||
console.timeEnd('box-and-client-' + N.toString()));
|
||||
}
|
||||
|
||||
new Ground(boot).start();
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env -S node --es-module-specifier-resolution=node
|
||||
//---------------------------------------------------------------------------
|
||||
// @syndicate-lang/core, an implementation of Syndicate dataspaces for JS.
|
||||
// Copyright (C) 2016-2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
assertion type BoxState(value);
|
||||
message type SetBox(newValue);
|
||||
|
||||
const N = 100000;
|
||||
|
||||
console.time('box-and-client-' + N.toString());
|
||||
|
||||
boot {
|
||||
spawn named 'box' {
|
||||
field this.value = 0;
|
||||
assert BoxState(this.value);
|
||||
dataflow {
|
||||
if (this.value === N) {
|
||||
stop {
|
||||
console.log('terminated box root facet');
|
||||
}
|
||||
}
|
||||
}
|
||||
on message SetBox($v) => this.value = v;
|
||||
}
|
||||
|
||||
spawn named 'client' {
|
||||
on asserted BoxState($v) => send SetBox(v + 1);
|
||||
on retracted BoxState(_) => console.log('box gone');
|
||||
}
|
||||
|
||||
thisFacet.actor.dataspace.addStopHandler(() =>
|
||||
console.timeEnd('box-and-client-' + N.toString()));
|
||||
}
|
Loading…
Reference in New Issue