objectPropsvalidators support async validators too. You can compose async validators together with any other validators. Here is an example showing sync and async validators mixed together with nested objects and validator arrays.
validateAsyncis resolved, all async validators will be resolved.
everyvalidator retains its short-circuiting behavior when async results are returned. Multiple async validators will be chained together such that the first async validator will complete before the next async validator is executed. This lets you chain validators to prevent subsequent validators from getting called if earlier validators are already invalid. But beware that multiple async validators in an array would then have their execution times added up before valid results can be returned.
allvalidator resolves all async prop validators in parallel. Because
allwill never short-circuit based on validation results, it uses
Promise.all()to resolve the validators. Its async validators can therefore run in parallel, and it may sometimes be beneficial to use
allexplicitly when performing multiple async validations.
somevalidator is similar to
every; it short-circuits and therefore cannot run async validators in parallel. The
somevalidator will short-circuit and return a valid result as soon as it encounters the first valid result. Async validators will therefore get chained together and run in series until a valid result is found.
arrayElementsvalidator resolves all array element validation in parallel. This is possible because all array elements are validated independently of each other, with no one element being invalid affecting the validation of other elements. The
arrayElementsvalidator result will not be resolved until all array elements have been validated, but the async validators will be executed in parallel using
Promise.all(). It is possible for validators to conditionally require async validation, which leads to the possibility of some array elements being validated synchronously and others required async validation.
objectPropsvalidator resolves all async prop validators in parallel. This is possible because one prop being invalid does not prevent other props from being validated. The
objectPropsvalidator result will not be resolved until all props have been validated, but the async validators will be executed in parallel using
Promise.all(). In the example above,
validateCityrun in parallel.