This commit is contained in:
Tony Garnock-Jones 2021-02-23 14:08:29 +01:00
parent ba2b2edfc3
commit ecef864793
1 changed files with 2 additions and 6 deletions

View File

@ -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)));
}
}