(id: string)
| 55 | } |
| 56 | |
| 57 | async pull(id: string): Promise<T> { |
| 58 | this.assertOpen(id) |
| 59 | |
| 60 | const items = this.queues.get(id) |
| 61 | |
| 62 | if (items?.length) { |
| 63 | const item = items.shift()! |
| 64 | |
| 65 | if (items.length === 0) { |
| 66 | this.queues.delete(id) |
| 67 | } |
| 68 | |
| 69 | return item |
| 70 | } |
| 71 | |
| 72 | return new Promise<T>((resolve, reject) => { |
| 73 | const waitingPulls = this.waiters.get(id) |
| 74 | |
| 75 | const pending = [resolve, reject] as const |
| 76 | |
| 77 | if (waitingPulls) { |
| 78 | waitingPulls.push(pending) |
| 79 | } |
| 80 | else { |
| 81 | this.waiters.set(id, [pending]) |
| 82 | } |
| 83 | }) |
| 84 | } |
| 85 | |
| 86 | close({ id, reason }: AsyncIdQueueCloseOptions = {}): void { |
| 87 | if (id === undefined) { |
no test coverage detected