Skip to content

Instantly share code, notes, and snippets.

@dtipson
Last active December 25, 2023 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtipson/e8184db4924cd532567ecfb8456d89d8 to your computer and use it in GitHub Desktop.
Save dtipson/e8184db4924cd532567ecfb8456d89d8 to your computer and use it in GitHub Desktop.
Revised batchTasks generator
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