Home Reference Source
import {ThreadPool} from 'rabbit-hole'
public class | source

ThreadPool

Extends:

three~EventDispatcher → ThreadPool

Implements:

Manages worker threads.

Constructor Summary

Public Constructor
public

constructor(maxWorkers: Number)

Constructs a new thread pool.

Member Summary

Public Members
public

A configuration message.

public

The maximum number of active worker threads.

Method Summary

Public Methods
public

clear()

Resets this thread pool by closing all workers.

public

closeWorker(worker: Worker)

Closes a worker.

public

Removes all active workers and releases the worker program blob.

public

getWorker(): Worker

Polls an available worker and returns it.

public

handleEvent(event: Event)

Handles events.

Public Constructors

public constructor(maxWorkers: Number) source

Constructs a new thread pool.

Params:

NameTypeAttributeDescription
maxWorkers Number
  • optional
  • default: navigator.hardwareConcurrency

Limits the amount of active workers. The default limit is the amount of logical processors.

Public Members

public configurationMessage: ConfigurationMessage source

A configuration message.

This object will be sent to each newly created worker.

public maxWorkers: Number source

The maximum number of active worker threads.

Public Methods

public clear() source

Resets this thread pool by closing all workers.

public closeWorker(worker: Worker) source

Closes a worker.

Params:

NameTypeAttributeDescription
worker Worker

The worker to close.

public dispose() source

Removes all active workers and releases the worker program blob.

public getWorker(): Worker source

Polls an available worker and returns it. The worker will be excluded from subsequent polls until it finishes its task and sends a message back.

Return:

Worker

A worker or null if all resources are currently exhausted.

public handleEvent(event: Event) source

Handles events.

Params:

NameTypeAttributeDescription
event Event

An event.