This commit is contained in:
Tony Garnock-Jones 2021-02-23 11:01:57 +01:00
parent c318aca51a
commit c8f040f3e4
1 changed files with 1 additions and 4 deletions

View File

@ -71,7 +71,6 @@ export class Turn {
readonly actor: Actor;
readonly queues: Map<Actor, LocalAction[]> = new Map();
readonly localActions: Array<LocalAction> = [];
completed = false;
static for(actor: Actor, f: (t: Turn) => void): void {
const t = new Turn(actor);
@ -137,9 +136,7 @@ export class Turn {
this.queues.get(actor)?.push(a) ?? this.queues.set(actor, [a]);
}
complete(): void {
if (this.completed) throw new Error("Reuse of completed Turn!");
this.completed = true;
private complete(): void {
this.queues.forEach((q, a) => a.execute(() => q.forEach(f => Turn.for(a, f))));
if (this.localActions.length > 0) {
queueMicrotask(() => this.localActions.forEach(f => Turn.for(this.actor, f)));