Cesium TaskProcessor vs Web Worker

I need to process a large amount of data. I was wondering if there are any reasons to use Cesium's TaskProcessor rather than a typical Web Worker?

Probably not. TaskProcessor is a wrapper around an array of Web Workers which defines a specific communication protocol that can adapt the web worker API to a promise-based API.

Basically, the page context posts a message describing what task work to do, along with an ID which the worker will then use to post back with the results when finished, allowing the page context to resolve the promise. There’s also logic to dynamically load AMD modules on the worker side, such that workers sort of transform themselves into the processor specific for a given task.

In practice, TaskProcessor is used internally in Cesium and not really designed for user extensibility. I would suggest simply using the Web Worker API directly yourself from your own code, which is really quite simple (postMessage to send a message, onmessage to receive one).

Interesting, so for adding a large amount of objects to the globe (thousands of polylines) should I use a Web Worker instead of the TaskProcessor? The goal is that the UI does not freeze.

Primitives in Cesium, when created with asynchronous set to true (the default), already delegate much of the work to a web worker automatically. WebGL requires resource creation to happen on the main thread, however, so that work can’t be moved to a worker. The best you can do is to create smaller batches of geometry and create them across several turns of the event loop (basically cooperative multitasking).

Thanks! OK, I guess that means that Entities (such as Polylines), which are not Primitives, are not created asynchronously.

If an Entity's availability property is set to be far in the future (making the entity currently invisible), can it be created asynchronously?

Entities, including those with PolylineGraphics, are created asynchronously if they are constant with respect to time, that is, if the properties defining the polyline return true from isConstant.