-
-
Notifications
You must be signed in to change notification settings - Fork 253
feat: support AbortSignal #1203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
A more universal approach I’ve just thought of is to use generic config and pass it as an additional parameter to the async actions. eg. v.parseAsync(
v.pipeAsync(
v.string(),
v.checkAsync(async (v, { signal, foo }) => {
console.log(foo) // 1
const res = await fetch("https://httpbin.org/delay/2", { signal })
return res.ok
}),
),
"123",
{
signal: AbortSignal.abort(),
foo: 1,
},
) Which approach would you prefer? |
Thank you for this PR! My plan is to provide general support for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds AbortSignal support across asynchronous validation and transformation flows, enabling early termination of pipes and checks.
- Introduces an optional
signal
in the sharedConfig
and propagates it through all async schemas and actions. - Updates
pipeAsync
,lazyAsync
,customAsync
,checkAsync
,transformAsync
,partialCheckAsync
, andcheckItemsAsync
to forward and respect the signal. - Extends tests to verify that getter functions and pipelines receive the signal and that aborting causes the proper errors.
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
library/src/types/config.ts | Added signal?: AbortSignal to Config |
library/src/storages/globalConfig/globalConfig.ts | Merged config.signal into the global config object |
library/src/storages/globalConfig/globalConfig.test.ts | Added default signal field in config tests |
library/src/schemas/lazy/lazyAsync.ts | Extended getter signature to accept signal |
library/src/schemas/lazy/lazyAsync.test.ts | Updated tests to assert signal is forwarded |
library/src/schemas/custom/customAsync.ts | Extended check callback to accept signal |
library/src/methods/pipe/pipeAsync.ts | Called config.signal?.throwIfAborted() before items |
library/src/methods/pipe/pipeAsync.test.ts | Added abortSignal test for pipeline |
library/src/methods/parse/parseAsync.test.ts | Added abortSignal test in parseAsync |
library/src/actions/types.ts | Updated ArrayRequirementAsync signature |
library/src/actions/transform/transformAsync.ts | Extended operation to accept signal |
library/src/actions/partialCheck/partialCheckAsync.ts | Extended requirement to accept signal |
library/src/actions/checkItems/checkItemsAsync.ts | Forwarded signal in map calls |
library/src/actions/check/checkAsync.ts | Extended requirement to accept signal |
Comments suppressed due to low confidence (2)
library/src/storages/globalConfig/globalConfig.test.ts:16
- [nitpick] The test only verifies the default
undefined
signal. Add a case wherestore.signal
is set (andconfig.signal
omitted) to ensure the fallback tostore.signal
works as expected.
signal: undefined,
library/src/storages/globalConfig/globalConfig.ts:38
- When merging global config, you should preserve a stored default signal if
config.signal
is undefined. Consider usingsignal: config?.signal ?? store?.signal
to maintain fallback behavior.
signal: config?.signal,
commit: |
Expected: