-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send requests to importer in batches
- Loading branch information
1 parent
8153a00
commit baad702
Showing
2 changed files
with
23 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Utility function to process requests in chunks | ||
export const processInBatches = async <T>( | ||
items: T[], | ||
batchSize: number, | ||
processFunc: (item: T) => Promise<any>, | ||
): Promise<any[]> => { | ||
const results: any[] = [] | ||
for (let index = 0; index < items.length; index += batchSize) { | ||
const batch = items.slice(index, index + batchSize) | ||
const batchResults = await Promise.all( | ||
batch.map((item) => processFunc(item)), | ||
) | ||
results.push(...batchResults) | ||
} | ||
return results | ||
} |