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.
参数名称 | 类型 | 默认值 | 描述信息 |
---|---|---|---|
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
|
可选 The maximum number of active tasks. Once exceeded, scheduleTask will not queue any more tasks, allowing work to be rescheduled in future frames. |
方法
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.
Posts a message to a web worker with configuration to initialize loading
and compiling a web assembly module asynchronously, as well as an optional
fallback JavaScript module to use if Web Assembly is not supported.
参数名称 | 类型 | 描述信息 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
webAssemblyOptions |
object |
可选
An object with the following properties:
|
返回值:
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.
Throws:
-
RuntimeError : This browser does not support Web Assembly, and no backup module was provided
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.
返回值:
True if this object was destroyed; otherwise, false.
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 |
object | Any input data that will be posted to the worker. |
transferableObjects |
Array.<Object> | 可选 An array of objects contained in parameters that should be transferred to the worker instead of copied. |
返回值:
Either a promise that will resolve to the result when available, or undefined
if there are too many active tasks,
使用示例:
const taskProcessor = new Cesium.TaskProcessor('myWorkerPath');
const promise = taskProcessor.scheduleTask({
someParameter : true,
another : 'hello'
});
if (!Cesium.defined(promise)) {
// too many active tasks - try again later
} else {
promise.then(function(result) {
// use the result of the task
});
}