TaskProcessor

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.

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 isDestroyed will result in a DeveloperError exception.
Returns:

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 isDestroyed will result in a DeveloperError exception.
Returns:
True if this object was destroyed; otherwise, false.
See:

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 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
    });
}