(id: string, item: T)
| 31 | } |
| 32 | |
| 33 | push(id: string, item: T): void { |
| 34 | this.assertOpen(id) |
| 35 | |
| 36 | const pending = this.waiters.get(id) |
| 37 | |
| 38 | if (pending?.length) { |
| 39 | pending.shift() |
| 40 | |
| 41 | if (pending.length === 0) { |
| 42 | this.waiters.delete(id) |
| 43 | } |
| 44 | } |
| 45 | else { |
| 46 | const items = this.queues.get(id) |
| 47 | |
| 48 | if (items) { |
| 49 | items.push(item) |
| 50 | } |
| 51 | else { |
| 52 | this.queues.set(id, [item]) |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | async pull(id: string): Promise<T> { |
| 58 | this.assertOpen(id) |