Asynchronous ground dataspace
This commit is contained in:
parent
70c2215de8
commit
a396432699
|
@ -21,6 +21,7 @@ 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 Struct = Syndicate.Struct;
|
const Struct = Syndicate.Struct;
|
||||||
const __ = Syndicate.__;
|
const __ = Syndicate.__;
|
||||||
const _$ = Syndicate._$;
|
const _$ = Syndicate._$;
|
||||||
|
@ -32,7 +33,7 @@ const N = 100000;
|
||||||
|
|
||||||
console.time('box-and-client-' + N.toString());
|
console.time('box-and-client-' + N.toString());
|
||||||
|
|
||||||
let ds = new Dataspace(() => {
|
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(() => {
|
||||||
|
@ -73,12 +74,6 @@ let ds = new Dataspace(() => {
|
||||||
return [Syndicate.Observe(BoxState(_$)), handler];
|
return [Syndicate.Observe(BoxState(_$)), handler];
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
}).start().stopHandler = () => {
|
||||||
|
console.timeEnd('box-and-client-' + N.toString());
|
||||||
// console.log('--- starting ---');
|
};
|
||||||
while (ds.runScripts()) {
|
|
||||||
// console.log('--- runScripts boundary ---');
|
|
||||||
}
|
|
||||||
// console.log('--- done ---');
|
|
||||||
|
|
||||||
console.timeEnd('box-and-client-' + N.toString());
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const Immutable = require('immutable');
|
||||||
|
const Dataspace = require('./dataspace.js').Dataspace;
|
||||||
|
|
||||||
|
function Ground(bootProc) {
|
||||||
|
this.stepperId = null;
|
||||||
|
this.stepping = false;
|
||||||
|
this.startingFuel = 1000;
|
||||||
|
this.dataspace = new Dataspace(bootProc);
|
||||||
|
this.stopHandler = function () {};
|
||||||
|
}
|
||||||
|
|
||||||
|
Ground.prototype.start = function () {
|
||||||
|
if (!this.stepperId) {
|
||||||
|
this.stepperId = setTimeout(() => {
|
||||||
|
this.stepperId = null;
|
||||||
|
this._step();
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
return this; // allows chaining start() immediately after construction
|
||||||
|
};
|
||||||
|
|
||||||
|
Ground.prototype._step = function () {
|
||||||
|
this.stepping = true;
|
||||||
|
try {
|
||||||
|
let stillBusy = false;
|
||||||
|
for (var fuel = this.startingFuel; fuel > 0; fuel--) {
|
||||||
|
stillBusy = this.dataspace.runScripts();
|
||||||
|
if (!stillBusy) break;
|
||||||
|
}
|
||||||
|
if (stillBusy) {
|
||||||
|
this.start();
|
||||||
|
} else {
|
||||||
|
if (this.stopHandler) {
|
||||||
|
this.stopHandler(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this.stepping = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ground.prototype.stop = function () {
|
||||||
|
if (this.stepperId) {
|
||||||
|
clearTimeout(this.stepperId);
|
||||||
|
this.stepperId = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.Ground = Ground;
|
|
@ -20,6 +20,7 @@
|
||||||
const Struct = require('./struct.js');
|
const Struct = require('./struct.js');
|
||||||
const Skeleton = require('./skeleton.js');
|
const Skeleton = require('./skeleton.js');
|
||||||
const Dataspace = require('./dataspace.js');
|
const Dataspace = require('./dataspace.js');
|
||||||
|
const Ground = require('./ground.js');
|
||||||
const Assertions = require('./assertions.js');
|
const Assertions = require('./assertions.js');
|
||||||
|
|
||||||
module.exports.Immutable = require('immutable');
|
module.exports.Immutable = require('immutable');
|
||||||
|
@ -33,6 +34,7 @@ module.exports._$ = Skeleton._$;
|
||||||
|
|
||||||
module.exports._Dataspace = Dataspace;
|
module.exports._Dataspace = Dataspace;
|
||||||
module.exports.Dataspace = Dataspace.Dataspace;
|
module.exports.Dataspace = Dataspace.Dataspace;
|
||||||
|
module.exports.Ground = Ground;
|
||||||
|
|
||||||
module.exports._Assertions = Assertions;
|
module.exports._Assertions = Assertions;
|
||||||
module.exports.Observe = Assertions.Observe;
|
module.exports.Observe = Assertions.Observe;
|
||||||
|
|
Loading…
Reference in New Issue