(task: () => Promise<T>)
| 2 | private pendingApply: Promise<unknown> | null = null |
| 3 | |
| 4 | apply<T>(task: () => Promise<T>): Promise<T> { |
| 5 | const previous = this.pendingApply ?? Promise.resolve() |
| 6 | const current = previous.catch(() => undefined).then(task) |
| 7 | this.pendingApply = current |
| 8 | |
| 9 | const clear = () => { |
| 10 | if (this.pendingApply === current) this.pendingApply = null |
| 11 | } |
| 12 | current.then(clear, clear) |
| 13 | |
| 14 | return current |
| 15 | } |
| 16 | |
| 17 | async waitForPending(): Promise<void> { |
| 18 | const pending = this.pendingApply |
no outgoing calls
no test coverage detected