new TaskProcessor(workerName, maximumActiveTasks)
A wrapper around a web worker that allows scheduling tasks for a given worker,
returning results asynchronously via a promise.
The Worker is not constructed until a task is scheduled.
Name | Type | Default | Description |
---|---|---|---|
workerName |
String | The name of the worker. This is expected to be a script in the Workers folder. | |
maximumActiveTasks |
Number |
5
|
optional The maximum number of active tasks. Once exceeded, scheduleTask will not queue any more tasks, allowing work to be rescheduled in future frames. |
Source:
Core/TaskProcessor.js, line 174
Methods
-
destroy() → undefined
-
Destroys this object. This will immediately terminate the Worker.
Once an object is destroyed, it should not be used; calling any function other thanisDestroyed
will result in aDeveloperError
exception.Returns:
Source: Core/TaskProcessor.js, line 265 -
isDestroyed() → Boolean
-
Returns true if this object was destroyed; otherwise, false.
If this object was destroyed, it should not be used; calling any function other thanisDestroyed
will result in aDeveloperError
exception.Returns:
True if this object was destroyed; otherwise, false.See:
Source: Core/TaskProcessor.js, line 253 -
scheduleTask(parameters, transferableObjects) → Promise
-
Schedule a task to be processed by the web worker asynchronously. If there are currently more tasks active than the maximum set by the constructor, will immediately return undefined. Otherwise, returns a promise that will resolve to the result posted back by the worker when finished.
Name Type Description parameters
* Any input data that will be posted to the worker. transferableObjects
Array.<Object> optional An array of objects contained in parameters that should be transferred to the worker instead of copied. Returns:
Either a promise that will resolve to the result when available, or undefined if there are too many active tasks,Example:
var taskProcessor = new Cesium.TaskProcessor('myWorkerName'); var promise = taskProcessor.scheduleTask({ someParameter : true, another : 'hello' }); if (!Cesium.defined(promise)) { // too many active tasks - try again later } else { Cesium.when(promise, function(result) { // use the result of the task }); }
Source: Core/TaskProcessor.js, line 210