Spaces:
Paused
Paused
Download src/lib/batch-process.ts from Echo-AI-official/Fire-crawl: direct link, hf CLI and curl.
- Browser
- Download file 425 Bytes
-
https://huggingface.co/spaces/Echo-AI-official/Fire-crawl/resolve/main/src/lib/batch-process.ts
- Command line
-
hf download hf://spaces/Echo-AI-official/Fire-crawl/src/lib/batch-process.ts
-
curl -L -o batch-process.ts https://huggingface.co/spaces/Echo-AI-official/Fire-crawl/resolve/main/src/lib/batch-process.ts
425 Bytes
| export async function batchProcess<T>( | |
| array: T[], | |
| batchSize: number, | |
| asyncFunction: (item: T, index: number) => Promise<void>, | |
| ): Promise<void> { | |
| const batches: T[][] = []; | |
| for (let i = 0; i < array.length; i += batchSize) { | |
| const batch = array.slice(i, i + batchSize); | |
| batches.push(batch); | |
| } | |
| for (const batch of batches) { | |
| await Promise.all(batch.map((item, i) => asyncFunction(item, i))); | |
| } | |
| } | |