| 19 | ) {} |
| 20 | |
| 21 | tick(trigger?: Call, source: "timer" | "post-tool" = "timer"): Promise<void> { |
| 22 | if (!this.active) return Promise.resolve(); |
| 23 | const next = this.queue.then(async () => { |
| 24 | if (this.error) throw this.error; |
| 25 | const before = this.actor.actions.length; |
| 26 | await this.actor.tick(this.now(), trigger, source); |
| 27 | if (this.actor.actions.length > before) await this.changed(this.actor.actions.slice(before)); |
| 28 | }); |
| 29 | this.queue = next.catch(error => { this.error = error instanceof Error ? error : new Error(String(error)); }); |
| 30 | return next; |
| 31 | } |
| 32 | |
| 33 | async close(): Promise<void> { |
| 34 | this.active = false; |