()
| 35 | ) {} |
| 36 | |
| 37 | async trigger(): Promise<void> { |
| 38 | this.lastTrigger = this.adapter.time; |
| 39 | if (this.queue.length === 0) { |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | if (this.scheduled !== null) { |
| 44 | this.scheduled.cancel = true; |
| 45 | } |
| 46 | |
| 47 | const scheduled = { |
| 48 | cancel: false, |
| 49 | }; |
| 50 | this.scheduled = scheduled; |
| 51 | |
| 52 | // Ensure that no task remains pending for longer than `this.maxDelay` ms. |
| 53 | const now = this.adapter.time; |
| 54 | const maxDelay = Math.max(0, (this.oldestScheduledAt ?? now) + this.maxDelay - now); |
| 55 | const delay = Math.min(maxDelay, this.delay); |
| 56 | |
| 57 | await this.adapter.timeout(delay); |
| 58 | |
| 59 | if (scheduled.cancel) { |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | this.scheduled = null; |
| 64 | |
| 65 | await this.execute(); |
| 66 | } |
| 67 | |
| 68 | async execute(): Promise<void> { |
| 69 | this.lastRun = this.adapter.time; |
no test coverage detected