parallel

async

Runs multiple async functions in parallel with a concurrency limit.

Signature

parallel<T>(tasks: (() => Promise<T>)[], limit?: number): Promise<T[]>

Parameters

NameTypeDescription
tasks(() => Promise<T>)[]Array of async functions to execute
limit?numberMaximum number of concurrent operationsDefault: 5

Returns

Promise<T[]> - Returns array of results in the same order as tasks

Examples

Parallel API calls

import { parallel } from 'dashlite'

const tasks = urls.map(url => () => fetch(url))
const results = await parallel(tasks, 3)

Concurrent operations

import { parallel } from 'dashlite'

const results = await parallel([
  () => apiCall1(),
  () => apiCall2(),
  () => apiCall3()
], 2)

Available since version 1.2.0