English中文

TaskProcessor

new Cesium.TaskProcessor(workerPath, maximumActiveTasks)

Web Worker 的包装器,允许为给定的 Worker 调度任务,通过 Promise 异步返回结果。在安排任务之前,不会构建 Worker。 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 工作人员的 URL。这可以是绝对路径,也可以是相对于 Cesium Workers 文件夹的路径。 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 活动任务的最大数量。一旦超出,scheduleTask 将不再排队任何任务,从而允许在未来的帧中重新安排工作。 The maximum number of active tasks. Once exceeded, scheduleTask will not queue any more tasks, allowing work to be rescheduled in future frames.

方法 Methods

销毁这个对象。这将立即终止该 Worker。 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.<*>

向 Web Worker 发布一条消息,其中包含用于初始化异步加载和编译 Web Assembly 模块的配置,以及在不支持 Web Assembly 时使用的可选后备 JavaScript 模块。 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.
名称 Name 类型 Type 说明 Description
webAssemblyOptions object 可选 optional 具有以下属性的对象: An object with the following properties:
名称 Name 类型 Type 说明 Description
modulePath string 可选 optional Web 程序集 JavaScript 包装器模块的路径。 The path of the web assembly JavaScript wrapper module.
wasmBinaryFile string 可选 optional Web 程序集二进制文件的路径。 The path of the web assembly binary file.
fallbackModulePath string 可选 optional 不支持 Web 程序集时要使用的后备 JavaScript 模块的路径。 The path of the fallback JavaScript module to use if web assembly is not supported.
返回: Returns:
当 Web Worker 加载并编译 Web 程序集模块并准备好处理任务时,该承诺会解析为结果。 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

isDestroyed()boolean

如果该对象被销毁则返回 true;否则为假。 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;否则为假。 True if this object was destroyed; otherwise, false.
另见: See:

scheduleTask(parameters, transferableObjects)Promise.<object>|undefined

安排由 Web Worker 异步处理的任务。如果当前活动的任务数量超过了构造函数设置的最大值,将立即返回 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.
名称 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:
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
    });
}
需要帮助吗?获得答案的最快方法是从社区和团队那里获得答案 Need help? The fastest way to get answers is from the community and team on the Cesium Forum.