Options
All
  • Public
  • Public/Protected
  • All
Menu

External module Executors

Index

Object literals

Object literals

Const Executors

Executors: object

Utility methods for creating different types of thread pools.

Example usage:

import { Executors } from "node-threadpool";
const pool = Executors.newFixedThreadPool(4);

// these execute in parallel (as long as the pool size >= 2)
const result1 = pool.submit(async () => "done 1");
const result2 = pool.submit(async () => "done 2");

console.log(await result1); // joins and prints "done1"
console.log(await result2); // joins and prints "done2"

newFixedThreadPool

  • Constructs a new fixed thread pool with the given number of threads.

    A fixed thread pool immediately creates its worker threads and maintains that set amount of threads. If a thread is terminated, threads will be recreated to maintain a fixed size.

    Work submitted to this thread pool will be handed to a thread if available. If all threads are busy, the work will be queued and executed in queue order as threads free up.

    Parameters

    • numThreads: number

    Returns IThreadPool

    A instance of IThreadPool

newSingleThreadedExecutor

  • Constructs a new thread pool with a single worker thread.

    Work submitted to this thread pool will be handed to the thread if available. If the thread is busy, the work will be queued and executed in queue order once the thread frees up.

    Returns IThreadPool

    A instance of IThreadPool

Generated using TypeDoc