-
-
Notifications
You must be signed in to change notification settings - Fork 302
Open
Labels
Milestone
Description
In the following code I expect that parsing will be stopped right away, because email field is not valid, and abortEarly is set to true. But parsing awaits for the whole 10 seconds before returning result.
Ideally I expect that promise will not be even started in that case.
And the related question:
Is there a way to abort running promise? Using AbortController or something?
import * as v from 'valibot';
const Schema = v.objectAsync({
email: v.pipe(v.string(), v.trim(), v.email()),
username: v.pipeAsync(
v.string(),
v.nonEmpty(),
v.maxLength(30),
v.checkAsync(() => new Promise((res) => {
console.log('request');
setTimeout(() => res(true), 10000)
}))
),
});
const result = await v.safeParseAsync(Schema, {
email: '',
username: 'qwerty',
}, {
abortEarly: true,
abortPipeEarly: true,
});
console.log(result);