Be stricter about facet-setup vs script phase separation
This commit is contained in:
parent
bae07566ca
commit
2c3d7d247d
|
@ -544,6 +544,9 @@ Message.prototype.perform = function (ds, ac) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Dataspace.send = function (body) {
|
Dataspace.send = function (body) {
|
||||||
|
if (!Dataspace._inScript) {
|
||||||
|
throw new Error("Cannot `send` during facet setup; are you missing an `on start { ... }`?");
|
||||||
|
}
|
||||||
Dataspace._currentFacet.enqueueScriptAction(new Message(body));
|
Dataspace._currentFacet.enqueueScriptAction(new Message(body));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -558,6 +561,9 @@ Spawn.prototype.perform = function (ds, ac) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Dataspace.spawn = function (name, bootProc, initialAssertions) {
|
Dataspace.spawn = function (name, bootProc, initialAssertions) {
|
||||||
|
if (!Dataspace._inScript) {
|
||||||
|
throw new Error("Cannot `spawn` during facet setup; are you missing an `on start { ... }`?");
|
||||||
|
}
|
||||||
Dataspace._currentFacet.enqueueScriptAction(new Spawn(name, bootProc, initialAssertions));
|
Dataspace._currentFacet.enqueueScriptAction(new Spawn(name, bootProc, initialAssertions));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -579,6 +585,9 @@ DeferredTurn.prototype.perform = function (ds, ac) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Dataspace.deferTurn = function (continuation) {
|
Dataspace.deferTurn = function (continuation) {
|
||||||
|
if (!Dataspace._inScript) {
|
||||||
|
throw new Error("Cannot defer turn during facet setup; are you missing an `on start { ... }`?");
|
||||||
|
}
|
||||||
Dataspace._currentFacet.enqueueScriptAction(new DeferredTurn(Dataspace.wrap(continuation)));
|
Dataspace._currentFacet.enqueueScriptAction(new DeferredTurn(Dataspace.wrap(continuation)));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -697,7 +706,17 @@ Facet.prototype.stop = function (continuation) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Facet.prototype.addStartScript = function (s) {
|
||||||
|
if (Dataspace._inScript) {
|
||||||
|
throw new Error("Cannot `on start` outside facet setup");
|
||||||
|
}
|
||||||
|
this.actor.scheduleScript(s);
|
||||||
|
};
|
||||||
|
|
||||||
Facet.prototype.addStopScript = function (s) {
|
Facet.prototype.addStopScript = function (s) {
|
||||||
|
if (Dataspace._inScript) {
|
||||||
|
throw new Error("Cannot `on stop` outside facet setup");
|
||||||
|
}
|
||||||
this.stopScripts = this.stopScripts.push(s);
|
this.stopScripts = this.stopScripts.push(s);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,9 @@ function inNestedDataspace(bootProc) {
|
||||||
const outerFacet = Dataspace.currentFacet();
|
const outerFacet = Dataspace.currentFacet();
|
||||||
outerFacet.addDataflow(function () {});
|
outerFacet.addDataflow(function () {});
|
||||||
// ^ eww! Dummy endpoint to keep the root facet of the relay alive.
|
// ^ eww! Dummy endpoint to keep the root facet of the relay alive.
|
||||||
const innerDs = new NestedDataspace(outerFacet, bootProc);
|
const innerDs = new NestedDataspace(outerFacet, function () {
|
||||||
|
Dataspace.currentFacet().addStartScript(() => bootProc.call(this));
|
||||||
|
});
|
||||||
innerDs.start();
|
innerDs.start();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,19 @@ export {
|
||||||
PacketRequest,
|
PacketRequest,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function onStartSpawnBufferStream() {
|
||||||
|
const id = genUuid('buffer-stream');
|
||||||
|
on start _spawnBufferStream(id);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
export function spawnBufferStream() {
|
export function spawnBufferStream() {
|
||||||
const id = genUuid('buffer-stream');
|
const id = genUuid('buffer-stream');
|
||||||
|
_spawnBufferStream(id);
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _spawnBufferStream(id) {
|
||||||
spawn named id {
|
spawn named id {
|
||||||
stop on retracted Observe(S.Duplex(id));
|
stop on retracted Observe(S.Duplex(id));
|
||||||
assert S.Duplex(id);
|
assert S.Duplex(id);
|
||||||
|
|
|
@ -30,7 +30,7 @@ assertion type Counter(id);
|
||||||
|
|
||||||
function counter() {
|
function counter() {
|
||||||
const id = genUuid();
|
const id = genUuid();
|
||||||
spawn named ['counter', id] {
|
on start spawn named ['counter', id] {
|
||||||
const rootFacet = currentFacet();
|
const rootFacet = currentFacet();
|
||||||
|
|
||||||
assert Counter(id);
|
assert Counter(id);
|
||||||
|
|
|
@ -17,7 +17,7 @@ spawn named 'socks-server' {
|
||||||
|
|
||||||
stop on retracted S.Duplex(conn);
|
stop on retracted S.Duplex(conn);
|
||||||
|
|
||||||
const buf = S.spawnBufferStream();
|
const buf = S.onStartSpawnBufferStream();
|
||||||
field this.bufferWanted = true;
|
field this.bufferWanted = true;
|
||||||
on start react {
|
on start react {
|
||||||
stop on (!this.bufferWanted);
|
stop on (!this.bufferWanted);
|
||||||
|
@ -210,8 +210,7 @@ spawn named 'remap-service' {
|
||||||
err.errno = err.code = 'ENOTFOUND';
|
err.errno = err.code = 'ENOTFOUND';
|
||||||
err.hostname = err.host = host;
|
err.hostname = err.host = host;
|
||||||
err.port = port;
|
err.port = port;
|
||||||
// TODO: should error because no 'on start':
|
on start send S.ConnectionRejected(id, err);
|
||||||
send S.ConnectionRejected(id, err);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
assert S.OutgoingConnection(id, S.TcpAddress(host, port));
|
assert S.OutgoingConnection(id, S.TcpAddress(host, port));
|
||||||
|
|
|
@ -439,7 +439,7 @@ export default declare((api, options) => {
|
||||||
PseudoEventHandler(path, state) {
|
PseudoEventHandler(path, state) {
|
||||||
const { node } = path;
|
const { node } = path;
|
||||||
if (node.triggerType === "start") {
|
if (node.triggerType === "start") {
|
||||||
path.replaceWith(template(`DATASPACE._currentFacet.actor.scheduleScript(() => {
|
path.replaceWith(template(`DATASPACE._currentFacet.addStartScript(() => {
|
||||||
BODY;
|
BODY;
|
||||||
});`)({
|
});`)({
|
||||||
DATASPACE: state.DataspaceID,
|
DATASPACE: state.DataspaceID,
|
||||||
|
|
Loading…
Reference in New Issue