Spaces:
Paused
Paused
Download node_modules/@huggingface/hub/src/utils/promisesQueue.ts from Leon4gr45/nova-header-nav: direct link, hf CLI and curl.
- Browser
- Download file 602 Bytes
-
https://huggingface.co/spaces/Leon4gr45/nova-header-nav/resolve/main/node_modules/%40huggingface/hub/src/utils/promisesQueue.ts
- Command line
-
hf download hf://spaces/Leon4gr45/nova-header-nav/node_modules/@huggingface/hub/src/utils/promisesQueue.ts
-
curl -L -o promisesQueue.ts https://huggingface.co/spaces/Leon4gr45/nova-header-nav/resolve/main/node_modules/%40huggingface/hub/src/utils/promisesQueue.ts
602 Bytes
| /** | |
| * Execute queue of promises. | |
| * | |
| * Inspired by github.com/rxaviers/async-pool | |
| */ | |
| export async function promisesQueue<T>(factories: (() => Promise<T>)[], concurrency: number): Promise<T[]> { | |
| const results: T[] = []; | |
| const executing: Set<Promise<void>> = new Set(); | |
| let index = 0; | |
| for (const factory of factories) { | |
| const closureIndex = index++; | |
| const e = factory().then((r) => { | |
| results[closureIndex] = r; | |
| executing.delete(e); | |
| }); | |
| executing.add(e); | |
| if (executing.size >= concurrency) { | |
| await Promise.race(executing); | |
| } | |
| } | |
| await Promise.all(executing); | |
| return results; | |
| } | |