Skip to content

parallel

The parallel function executes multiple asynchronous functions in parallel and returns a resolved Promise when all have finished.

Syntax

typescript
await parallel(...callbacks)

Parameters

NameTypeDescription
callbacksFunction[]List of asynchronous functions to be executed.

Return Value

TypeDescription
PromiseResolves with an array of the results of all functions.

Examples

typescript
await parallel(
  () => fetch('/api/1'),
  () => fetch('/api/2'),
  () => fetch('/api/3')
);

// Or using then:
parallel(
  () => fetch('/api/1'),
  () => fetch('/api/2')
).then(results => console.log(results));

Notes

  • Throws a TypeError if any of the arguments is not a function.
  • Useful for executing asynchronous tasks simultaneously and waiting for all to complete.

References

Released under the MIT License.