beermanB
Deno12mo ago
11 replies
beerman

batching tasks

I'm calling an api and get an array of 2000+ items. I want to chunk these into batches of 100 and then process them all concurrently.

I've tried BatchQueue but it looks like it stops after processing only the first batch.

const batchQueue = new BatchQueue(100)
const data = await response.json() as ApiResponse[];

let processedCount = 0;

this.batchQueue.queue(
  ...data.map((spin) => async () => {
    try {
      await this.processSpin(spin);
      processedCount++;
    } catch (error) {
        console.error(error);
    }
  }),
);

await this.batchQueue.run();


What's the best way to do this preferably without third party modules?
Was this page helpful?