Add AbortSignal support to all async Collection methods#18
Merged
Conversation
4 tasks
Every async method now accepts an optional `{ signal }` and forwards
it to the underlying driver call:
- find / findOne — { signal } added to find options
- exists / count / distinct — new options arg with signal
- save — signal forwarded to both insertOne and replaceOne paths
- saveAll — signal forwarded to insertMany
- update — new options arg with signal (plays nicely with existing
third-arg surface)
- remove / removeById — new options arg with signal
When the signal is already aborted (or fires mid-flight), the driver
throws AbortError, which the existing try/catch collapses into the
method's empty default + _emit. The fail-silent contract is unchanged.
Callers that need to distinguish "aborted" from "empty result" check
`signal.aborted` after the await — same pattern Node uses for
fs/promises and other AbortController-aware APIs.
findById is intentionally not extended — its second positional arg is
already overloaded (fields shortcut). Callers that need signal-aware
id lookup use findOne({ id }, { signal }) directly; the `id` alias is
recognised by prepare().
9a83b75 to
191b267
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Every async method on
Collectionnow accepts an optional{ signal }and forwards it to the underlying driver call:find/findOne—signaladded to find options.exists/count/distinct— new options arg with signal.save— signal forwarded to bothinsertOneandreplaceOnepaths.saveAll— signal forwarded toinsertMany.update— new options arg with signal (plays nicely with existing third-arg surface from update(): forward arrayFilters to the driver #17).remove/removeById— new options arg with signal.When the signal is already aborted (or fires mid-flight), the driver throws
AbortError, which the existing try/catch collapses into the method's empty default +_emit. The fail-silent contract is unchanged — public methods still never throw.Callers that need to distinguish "aborted" from "empty result" check
signal.abortedafter the await — same pattern Node uses forfs/promisesand other AbortController-aware APIs.findByIdis intentionally not extended — its second positional arg is already overloaded (fields shortcut). Callers that need signal-aware id lookup usefindOne({ id }, { signal })directly; theidalias is recognised byprepare().Test plan
pnpm test— all 129 tests pass (13 new intest/abort-signal.jscovering pre-aborted, mid-flight, fresh-signal-as-noop, and abort-detection-via-signal.aborted).pnpm lint— clean.pnpm format:check— clean.Context
Part of the yamb wishlist landing — see
plan/yamb-architecture-decisions.mdonfeature/yamb-request. Required for the storage contract's cancellation semantics, and a prerequisite for the upcomingfindCursorPR.