Last active
December 25, 2023 19:42
-
-
Save dtipson/e8184db4924cd532567ecfb8456d89d8 to your computer and use it in GitHub Desktop.
Revised batchTasks generator
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
export async function* batchTasks(tasks = [], limit = 5, taskCallback = r => r) { | |
for (let i = 0; i < tasks.length; i = i + limit) { | |
const batch = tasks.slice(i, i + limit) | |
yield* await Promise.all( | |
batch.map((task) => task().then(taskCallback)) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment