(key: string, factory: () => Promise<T>)
| 62 | } |
| 63 | |
| 64 | push<T>(key: string, factory: () => Promise<T>): Promise<T> { |
| 65 | if (this.first) { |
| 66 | this.first = false; |
| 67 | } else { |
| 68 | this.stillActive(); |
| 69 | } |
| 70 | |
| 71 | return new Promise((resolve, reject) => { |
| 72 | // we're already running so push ourselves to the queue |
| 73 | const queue = (this.queue[key] = this.queue[key] || []); |
| 74 | queue.push({factory, resolve, reject}); |
| 75 | |
| 76 | if (!this.running[key]) { |
| 77 | this.shift(key); |
| 78 | } |
| 79 | }); |
| 80 | } |
| 81 | |
| 82 | shift(key: string) { |
| 83 | if (this.running[key]) { |