Skip to content

createLimit

createLimit(concurrency): Limit

Defined in: packages/synapse-core/src/utils/concurrency.ts:22

Create a limit that runs at most concurrency tasks at a time, in call order.

ParameterTypeDescription
concurrencynumberThe maximum number of tasks running at the same time. Infinity means no limit.

Limit

A function that runs a task when a slot is free and resolves with its result.

import { createLimit } from '@filoz/synapse-core/utils'
const limit = createLimit(2)
const results = await Promise.all(urls.map((url) => limit(() => fetch(url))))