# TaskProcessor

#### new Cesium.TaskProcessor(workerPath, maximumActiveTasks)
Core/TaskProcessor.js 202

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
--- | --- | --- | ---
`workerPath` | String |  | The Url to the worker. This can either be an absolute path or relative to the Cesium Workers folder.
`maximumActiveTasks` | Number | `Number.POSITIVE_INFINITY` | 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()
Core/TaskProcessor.js 349

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.

#### initWebAssemblyModule(webAssemblyOptions) → Promise.<Object>
Core/TaskProcessor.js 293

Posts a message to a web worker with configuration to initialize loading and compiling a web assembly module asychronously, as well as an optional fallback JavaScript module to use if Web Assembly is not supported.

Name | Type | Description
--- | --- | ---
`webAssemblyOptions` | Object | optional An object with the following properties:
Name | Type | Description
--- | --- | ---
`modulePath` | String | optional The path of the web assembly JavaScript wrapper module.
`wasmBinaryFile` | String | optional The path of the web assembly binary file.
`fallbackModulePath` | String | optional The path of the fallback JavaScript module to use if web assembly is not supported.

##### Returns:

A promise that resolves to the result when the web worker has loaded and compiled the web assembly module and is ready to process tasks.

#### isDestroyed() → Boolean
Core/TaskProcessor.js 339

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:

- TaskProcessor#destroy

#### scheduleTask(parameters, transferableObjects) → Promise.<Object>|undefined
Core/TaskProcessor.js 243

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` | Object | 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('myWorkerPath');
    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
        });
    }