⚡ Asynchronous version of `Array.prototype.every`.
Info
By default, it runs all iterations in parallel. You can limit the concurrency by providing a third argument.
Syntax
TypeScript
import { everyAsync } from '@opentf/std'; everyAsync<T>( arr: T[], cb: (value: T, index: number) => Promise<boolean>, concurrency?: number ): Promise<boolean>;
Parameters
arr: The array to iterate over.cb: An async predicate that returns a boolean.concurrency(Optional): The maximum number of concurrent executions. Default:Infinity.
Returns
A Promise that resolves to true if every element satisfied the predicate, else false. An empty array is vacuously true.
Once an element fails, no further ones are started — though those already running are awaited, since work handed to the callback cannot be recalled.
Sparse array holes are skipped, matching native Array.prototype.every() behavior.
Examples
TypeScript
await everyAsync([2, 4, 6], async (n) => n % 2 === 0); //=> true
Stop as soon as one health check fails:
TypeScript
const allUp = await everyAsync( urls, async (url) => (await fetch(url)).ok, 4, ); //=> false