* Queue a load with concurrency limiting.
(imageFile: File, cacheKey: string)
| 190 | * Queue a load with concurrency limiting. |
| 191 | */ |
| 192 | function queueLoad(imageFile: File, cacheKey: string): Promise<T | null> { |
| 193 | const generation = state.cacheGeneration; |
| 194 | |
| 195 | return new Promise((resolve) => { |
| 196 | const doLoad = () => { |
| 197 | if (generation !== state.cacheGeneration) { |
| 198 | // clear() was called - it already reset activeLoads, don't decrement |
| 199 | resolve(null); |
| 200 | return; |
| 201 | } |
| 202 | loadFromFile(imageFile, cacheKey, generation).then(resolve); |
| 203 | }; |
| 204 | |
| 205 | if (state.activeLoads < MAX_CONCURRENT_LOADS) { |
| 206 | state.activeLoads++; |
| 207 | doLoad(); |
| 208 | } else { |
| 209 | state.pendingQueue.push(() => doLoad()); |
| 210 | } |
| 211 | }); |
| 212 | } |
| 213 | |
| 214 | return { |
| 215 | /** |
no test coverage detected