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
Name | Type | Description |
---|---|---|
...startupTasks | ThreadTask [] | 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
Name | Type |
---|---|
...tasks | ThreadTask [] |
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
Name | Type | Default value | Description |
---|---|---|---|
task | ThreadTask | undefined | |
queue | boolean | true | Wether 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