Appearance
KBE3D / KBCore / Cesium / TaskProcessor
类: TaskProcessor
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.
参数
The Url to the worker. This can either be an absolute path or relative to the Cesium Workers folder.
参数
The maximum number of active tasks. Once exceeded, scheduleTask will not queue any more tasks, allowing work to be rescheduled in future frames.
方法
scheduleTask()
scheduleTask(
parameters:any,transferableObjects?:object[]):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
any
Any input data that will be posted to the worker.
transferableObjects?
object[]
An array of objects contained in parameters that should be transferred to the worker instead of copied.
返回
Promise<object> | undefined
Either a promise that will resolve to the result when available, or undefined if there are too many active tasks,
示例
ts
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
});
}initWebAssemblyModule()
initWebAssemblyModule(
webAssemblyOptions?: {modulePath?:string;wasmBinaryFile?:string;fallbackModulePath?:string; }):Promise<any>
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?
An object with the following properties:
modulePath?
string
The path of the web assembly JavaScript wrapper module.
wasmBinaryFile?
string
The path of the web assembly binary file.
fallbackModulePath?
string
The path of the fallback JavaScript module to use if web assembly is not supported.
返回
Promise<any>
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()
isDestroyed():
boolean
Returns true if this object was destroyed; otherwise, false. <br /><br /> If this object was destroyed, it should not be used; calling any function other than <code>isDestroyed</code> will result in a DeveloperError exception.
返回
boolean
True if this object was destroyed; otherwise, false.
destroy()
destroy():
void
Destroys this object. This will immediately terminate the Worker. <br /><br /> Once an object is destroyed, it should not be used; calling any function other than <code>isDestroyed</code> will result in a DeveloperError exception.
返回
void
构造函数
构造函数
new TaskProcessor(
workerPath:string,maximumActiveTasks?:number):TaskProcessor
参数
workerPath
string
maximumActiveTasks?
number
返回
TaskProcessor
