diff --git a/actor.ts b/actor.ts index 5c9d47b..71d3abe 100644 --- a/actor.ts +++ b/actor.ts @@ -80,13 +80,11 @@ type LocalAction = (t: Turn) => void; export class Turn { readonly actor: Actor; readonly queues: Map = new Map(); - readonly tasks: Array = []; static for(actor: Actor, f: LocalAction): void { const t = new Turn(actor); f(t); t.queues.forEach((q, a) => a.execute(() => q.forEach(f => Turn.for(a, f)))); - t.tasks.length && queueMicrotask(() => t.tasks.forEach(f => Turn.for(actor, f))); } private constructor(actor: Actor) { @@ -98,7 +96,7 @@ export class Turn { } spawn(bootProc: LocalAction, initialAssertions = new IdentitySet()): void { - this.enqueue(void 0, () => { + this.enqueue(this.actor, () => { const newOutbound: OutboundMap = new Map(); initialAssertions.forEach(key => { newOutbound.set(key, this.actor.outbound.get(key)!); // we trust initialAssertions @@ -110,7 +108,7 @@ export class Turn { } quit(): void { - this.enqueue(void 0, t => this.actor.terminateWith(t, { ok: true })); + this.enqueue(this.actor, t => this.actor.terminateWith(t, { ok: true })); } assert(ref: Ref, assertion: Assertion): Handle { @@ -148,8 +146,7 @@ export class Turn { this.enqueue(ref.relay, t => ref[message]?.(t, assertion)); } - enqueue(relay: Actor | undefined, a: LocalAction): void { - (relay === void 0) ? this.tasks.push(a) - : this.queues.get(relay)?.push(a) ?? this.queues.set(relay, [a]); + enqueue(relay: Actor, a: LocalAction): void { + this.queues.get(relay)?.push(a) ?? this.queues.set(relay, [a]); } }