Batch Processing

Execute multiple operations independently.

If you need to execute a list of operations and collect all their results, without letting a single failure stop the entire batch, you can use the batch utilities.

Use catchErrorAll for an array of Promises or asynchronous functions. It waits for all of them to finish and returns an array of Result objects.

batch-async.ts
import { catchErrorAll } from '@catcherjs/core';

async function processTasks() {
const tasks = [
Promise.resolve('Task 1 complete'),
Promise.reject(new Error('Task 2 failed')),
Promise.resolve('Task 3 complete')
];

  const results = await catchErrorAll(tasks);

  results.forEach(result => {
      if (result.isOk()) {
          console.log(result.data);
      } else {
          console.error(result.error.message);
      }
  });

}

Use catchErrorAllSync for an array of synchronous functions. It executes them sequentially and returns an array of Result objects.

batch-sync.ts
import { catchErrorAllSync } from '@catcherjs/core';

function parseMultiple() {
const inputs = [
() => JSON.parse('{"a": 1}'),
() => JSON.parse('invalid'),
() => JSON.parse('{"c": 3}')
];

  const results = catchErrorAllSync(inputs);

  const successfulParses = results
      .filter(r => r.isOk())
      .map(r => r.data);

  console.log(successfulParses);

}

Component props

Prop
Type
Default

Component props

Prop
Type
Default