From ed8adae3f2d5285dd6ad63367a740852d01070b1 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Fri, 24 Dec 2021 17:29:26 -0500 Subject: [PATCH] Experiment: run facet teardown in the current turn, immediately, instead of delayed --- packages/core/src/runtime/actor.ts | 33 +++++++++++++----------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/packages/core/src/runtime/actor.ts b/packages/core/src/runtime/actor.ts index e4269f7..e516bec 100644 --- a/packages/core/src/runtime/actor.ts +++ b/packages/core/src/runtime/actor.ts @@ -117,14 +117,14 @@ export class Actor { this.exitHooks.push(a); } - terminateWith(reason: Exclude) { + _terminateWith(reason: Exclude) { if (this.exitReason !== null) return; this.exitReason = reason; if (!reason.ok) { console.error(`${this} crashed:`, reason.err); } this.exitHooks.forEach(hook => hook()); - queueTask(() => Turn.for(this.root, () => this.root._terminate(reason.ok), true)); + this.root._terminate(reason.ok); } repairDataflowGraph() { @@ -207,15 +207,13 @@ export class Facet { this.outbound.forEach(e => Turn.active._retract(e)); if (orderly) { - queueTask(() => { - if (parent) { - if (parent.isInert()) { - Turn.for(parent, () => parent._terminate(true)); - } - } else { - Turn.for(this.actor.root, () => this.actor.terminateWith({ ok: true }), true); + if (parent) { + if (parent.isInert()) { + parent._terminate(true); } - }); + } else { + this.actor._terminateWith({ ok: true }); + } } }); } @@ -278,7 +276,7 @@ export class Turn { } t.deliver(); } catch (err) { - Turn.for(facet.actor.root, () => facet.actor.terminateWith({ ok: false, err })); + Turn.for(facet.actor.root, () => facet.actor._terminateWith({ ok: false, err })); } } @@ -314,14 +312,11 @@ export class Turn { } stop(facet: Facet = this.activeFacet, continuation?: LocalAction) { - const facetParent = facet.parent; - if (facetParent === null) { + if (facet.parent === null) { this.stopActor(); } else { - this.enqueue(facet, () => { - if (continuation) facet.onStop(continuation); - facet._terminate(true); - }); + if (continuation) facet.onStop(continuation); + facet._terminate(true); } } @@ -361,11 +356,11 @@ export class Turn { } stopActor(): void { - this.enqueue(this.activeFacet.actor.root, () => this.activeFacet.actor.terminateWith({ ok: true })); + this.enqueue(this.activeFacet.actor.root, () => this.activeFacet.actor._terminateWith({ ok: true })); } crash(err: Error): void { - this.enqueue(this.activeFacet.actor.root, () => this.activeFacet.actor.terminateWith({ ok: false, err })); + this.enqueue(this.activeFacet.actor.root, () => this.activeFacet.actor._terminateWith({ ok: false, err })); } field, T = Ref>(initial: V, name?: string): Field {