Skip to content

feat: add error strategy option to batch resolver#26

Merged
JaysonGCS merged 1 commit into
mainfrom
feat/batch-resolver-error-strategy
May 30, 2026
Merged

feat: add error strategy option to batch resolver#26
JaysonGCS merged 1 commit into
mainfrom
feat/batch-resolver-error-strategy

Conversation

@JaysonGCS

Copy link
Copy Markdown
Contributor

Description

Adds a configurable errorStrategy to the batch resolver so callers can choose how errors propagate across a batch. Previously, any error from the batch resolver was always broadcast to every caller in the batch, meaning a single failing item could reject unrelated callers.

Changes Made

  • Added an errorStrategy option ('broadcast' | 'isolate') to BatchOptions.
  • broadcast (default): preserves existing behaviour — a resolver error rejects all callers in the batch.
  • isolate: the batch resolver returns per-item promises (Promise<TReturnType>[]), so each caller settles independently. Failed or cancelled callers bail immediately without affecting the rest of the batch.
  • Updated batchResolver to accept both AsyncBatchFunction and the new AsyncIsolateBatchFunction signature.
  • Updated the interception logic to handle per-item settlement, including releaseWithError per item and correct _activeBatchCount accounting; synchronous throws from the resolver still broadcast.
  • Added types/constants for the new strategy.
  • Added tests in src/index.test.ts covering isolate vs broadcast behaviour.
  • Updated README.md documentation and the examples/webapp demo (api client, config panel, defaults) to exercise the new option.

Definition of Done

  • All automated tests have passed successfully.
  • All manual tests have passed successfully.
  • Code has been reviewed by at least one other team member.
  • Code has been properly documented and commented as needed.
  • All new and existing code adheres to our project's coding standards.
  • All dependencies have been added or removed from the project's README or other documentation as needed.
  • Any relevant documentation or help files have been updated to reflect the changes made in this pull request.
  • Any necessary database migrations have been run.
  • Any relevant UI changes have been reviewed and approved by the UI/UX team.

Additional Notes

Default behaviour is unchanged (broadcast), so this is a backwards-compatible, additive feature.

Introduce an errorStrategy option ('broadcast' | 'isolate') for the batch
resolver. In 'isolate' mode the resolver returns per-item promises so each
caller settles independently, allowing failed/cancelled callers to bail
immediately instead of having errors broadcast to the whole batch.
'broadcast' remains the default and preserves existing behaviour.

Signed-off-by: JaysonGCS <goh.chung.sern@gmail.com>
@JaysonGCS JaysonGCS merged commit 4b1ae94 into main May 30, 2026
9 checks passed
@JaysonGCS JaysonGCS deleted the feat/batch-resolver-error-strategy branch May 30, 2026 15:30
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant