diff --git a/actor.ts b/actor.ts index f1da5c5..b5d1424 100644 --- a/actor.ts +++ b/actor.ts @@ -71,7 +71,8 @@ export class Turn { static for(actor: Actor, f: LocalAction): void { const t = new Turn(actor); f(t); - t.complete(); + 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) { @@ -135,9 +136,4 @@ export class Turn { enqueue(actor: Actor, a: LocalAction): void { this.queues.get(actor)?.push(a) ?? this.queues.set(actor, [a]); } - - private complete(): void { - this.queues.forEach((q, a) => a.execute(() => q.forEach(f => Turn.for(a, f)))); - this.tasks.length && queueMicrotask(() => this.tasks.forEach(f => Turn.for(this.actor, f))); - } }