Spaces:
Paused
Paused
Download node_modules/@huggingface/hub/src/utils/promisesQueueStreaming.ts from Leon4gr45/nova-header-nav: direct link, hf CLI and curl.
- Browser
- Download file 687 Bytes
-
https://huggingface.co/spaces/Leon4gr45/nova-header-nav/resolve/main/node_modules/%40huggingface/hub/src/utils/promisesQueueStreaming.ts
- Command line
-
hf download hf://spaces/Leon4gr45/nova-header-nav/node_modules/@huggingface/hub/src/utils/promisesQueueStreaming.ts
-
curl -L -o promisesQueueStreaming.ts https://huggingface.co/spaces/Leon4gr45/nova-header-nav/resolve/main/node_modules/%40huggingface/hub/src/utils/promisesQueueStreaming.ts
687 Bytes
| /** | |
| * Execute queue of promises in a streaming fashion. | |
| * | |
| * Optimized for streaming: | |
| * - Expects an iterable as input | |
| * - Does not return a list of all results | |
| * | |
| * Inspired by github.com/rxaviers/async-pool | |
| */ | |
| export async function promisesQueueStreaming<T>( | |
| factories: AsyncIterable<() => Promise<T>> | Iterable<() => Promise<T>>, | |
| concurrency: number, | |
| ): Promise<void> { | |
| const executing: Promise<void>[] = []; | |
| for await (const factory of factories) { | |
| const e = factory().then(() => { | |
| executing.splice(executing.indexOf(e), 1); | |
| }); | |
| executing.push(e); | |
| if (executing.length >= concurrency) { | |
| await Promise.race(executing); | |
| } | |
| } | |
| await Promise.all(executing); | |
| } | |