Class ThreadPool

Simple thread pool with a microtask-based queue.

Timer-free: browsers clamp nested setTimeout(0) to several ms, which stalls queued tasks.

Hierarchy

  • ThreadPool

Constructors

  • Construct the thread pool.

    Parameters

    • Optional maxConcurrency: any

      maximum number of threads in the pool (default 1)

    Returns ThreadPool

Properties

drainListeners: (() => void)[]

Type declaration

    • (): void
    • Returns void

maxConcurrency: number
numRunning: number
queueHead: any
queueTail: any

Methods

  • Await all functions to complete.

    Returns Promise<void>

    resolves when all functions complete

  • Returns void

  • Submit an asynchronous function to run using the thread pool.

    Type Parameters

    • T

    Parameters

    • asyncFn: (() => Promise<T>)

      asynchronous function to run with the thread pool

        • (): Promise<T>
        • Returns Promise<T>

    Returns Promise<T>

    resolves when the function completes execution

Generated using TypeDoc