blaze-2d
Version:
A fast and simple WebGL 2 2D game engine written in TypeScript
40 lines (39 loc) • 1.32 kB
TypeScript
import Thread, { ThreadTask } from "./thread";
export default class ThreadPool {
cores: number;
threads: Thread[];
private poolQueue;
poolingRate: number;
/**
* Creates a {@link ThreadPool} instance, executes any provided startup tasks on it's threads and starts it's cleaning loop.
*
* @param startupTasks Tasks to run on each created thread.
*/
constructor(...startupTasks: ThreadTask[]);
/**
* 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.
*
* @param task
* @param queue Wether or not to add the task to the queue if no thread is open
* @returns true/false depending on wether an open thread was found
*/
requestThread(task: ThreadTask, queue?: boolean): boolean;
/**
* Adds every provided task to every thread's queue, ignoring queue size limits.
*
* @param tasks
*/
everyThread(...tasks: ThreadTask[]): void;
/**
* Moves as many tasks as possible from the pool queue to open threads
*/
private cleanPool;
/**
* Gets the length of the pool's queue.
*
* @returns The pool's queue length
*/
getQueueLength(): number;
}