Skip to main content

parallelLimit

Callable

  • parallelLimit(maxConcurrency: number): <T>(task: () => T | Promise<T>) => Promise<T>

  • Creates a limit function that allows you to schedule promises that execute with a maximum concurrency.

    Example

    const limit = parallelLimit(2)
    const tasks = [
    limit(async () => {
    await sleep(100)
    return 1
    }),
    limit(() => 2),
    limit(() => 3),
    ]
    await Promise.all(tasks)
    // => [1, 2, 3]

    Alternatives


    Parameters

    • maxConcurrency: number

    Returns <T>(task: () => T | Promise<T>) => Promise<T>

    A limit function.

      • <T>(task: () => T | Promise<T>): Promise<T>
      • Type parameters

        • T

        Parameters

        • task: () => T | Promise<T>

        Returns Promise<T>