Skip to main content

Class: ThreadPool

threading/threadPool.ThreadPool

Constructors

constructor

โ€ข new ThreadPool(...startupTasks)

Creates a ThreadPool instance, executes any provided startup tasks on it's threads and starts it's cleaning loop.

Parameters

NameTypeDescription
...startupTasksThreadTask[]Tasks to run on each created thread.

Defined in

src/threading/threadPool.ts:15

Properties

cores

โ€ข cores: number

Defined in

src/threading/threadPool.ts:4


poolQueue

โ€ข Private poolQueue: ThreadTask[] = []

Defined in

src/threading/threadPool.ts:7


poolingRate

โ€ข poolingRate: number = 2000

Defined in

src/threading/threadPool.ts:8


threads

โ€ข threads: Thread[] = []

Defined in

src/threading/threadPool.ts:5

Methods

cleanPool

โ–ธ Private cleanPool(): void

Moves as many tasks as possible from the pool queue to open threads

Returns

void

Defined in

src/threading/threadPool.ts:66


everyThread

โ–ธ everyThread(...tasks): void

Adds every provided task to every thread's queue, ignoring queue size limits.

Parameters

NameType
...tasksThreadTask[]

Returns

void

Defined in

src/threading/threadPool.ts:55


getQueueLength

โ–ธ getQueueLength(): number

Gets the length of the pool's queue.

Returns

number

The pool's queue length

Defined in

src/threading/threadPool.ts:85


requestThread

โ–ธ requestThread(task, queue?): boolean

Attempts to run or queue the task on the best open thread (shortest queue)

Even when return value is false, the task is still added to the pool's queue to await execution.

Parameters

NameTypeDefault valueDescription
taskThreadTaskundefined
queuebooleantrueWether or not to add the task to the queue if no thread is open

Returns

boolean

true/false depending on wether an open thread was found

Defined in

src/threading/threadPool.ts:33