new TaskProcessor(workerName, maximumActiveTasksopt)
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.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
workerName |
String | The name of the worker. This is expected to be a script in the Workers folder. | ||
maximumActiveTasks |
Number |
<optional> |
5 | The maximum number of active tasks. Once exceeded, scheduleTask will not queue any more tasks, allowing work to be rescheduled in future frames. |
- Source:
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 than
Once an object is destroyed, it should not be used; calling any function other than
isDestroyed
will result in a DeveloperError
exception.
- Source:
Returns:
- Type
- undefined
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 than
If this object was destroyed, it should not be used; calling any function other than
isDestroyed
will result in a DeveloperError
exception.
- Source:
- See:
Returns:
True if this object was destroyed; otherwise, false.
- Type
- Boolean
scheduleTask(parameters, transferableObjectsopt) → {Promise.<Object>|undefined}
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.
Parameters:
Name | Type | Attributes | 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. |
- Source:
Returns:
Either a promise that will resolve to the result when available, or undefined
if there are too many active tasks,
- Type
- Promise.<Object> | undefined
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
});
}