Skip to content

Instantly share code, notes, and snippets.

@dtipson
Last active December 25, 2023 19:42
Show Gist options
  • Select an option

  • Save dtipson/e8184db4924cd532567ecfb8456d89d8 to your computer and use it in GitHub Desktop.

Select an option

Save dtipson/e8184db4924cd532567ecfb8456d89d8 to your computer and use it in GitHub Desktop.

Revisions

  1. dtipson revised this gist Dec 25, 2023. No changes.
  2. dtipson created this gist Dec 25, 2023.
    8 changes: 8 additions & 0 deletions batchTasks-spread.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    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))
    )
    }
    }