flywave-mapview.workerloader
Home > @flywave/flywave-mapview > WorkerLoader
WorkerLoader class
Set of Worker loading and initialization helpers: - starting Worker from URL with fallback to XHR+blob WorkerLoader.startWorker() - waiting for proper worker initialization, see WorkerLoader.waitWorkerInitialized()
Signature:
export declare class WorkerLoader
Properties
Property | Modifiers | Type | Description |
|---|---|---|---|
| Record<string, string> | ||
| boolean | ||
| Map<string, Promise<string>> |
Methods
Method | Modifiers | Description |
|---|---|---|
| Fetch script source as Reuses results, if there are many simultaneous requests. | |
| Starts worker by first attempting load from We must resolve/reject promise at some time, so it is expected that any sane application will be able to load worker code in some amount of time. By default, this method timeouts after 10 seconds (configurable using This method is needed as browsers in general forbid to load worker if it's not on 'same origin' regardless of Content-Security-Policy. For blob-based fallback work, one need to ensure that Content Security Policy (CSP) allows loading web worker code from Following snippet setups CSP, so workers can be started from blob urls: Tested on: * Chrome 67 / Linux, Window, OSX, Android * Firefox 60 / Linux, Windows, OSX * Edge 41 / Windows * Safari 11 / OSX * Samsung Internet 7.2 See * https://benohead.com/cross-domain-cross-browser-web-workers/ * MapBox * https://stackoverflow.com/questions/21913673/execute-web-worker-from-different-origin * https://github.com/mapbox/mapbox-gl-js/issues/2658 * https://github.com/mapbox/mapbox-gl-js/issues/559 * https://github.com/mapbox/mapbox-gl-js/issues/6058 Findings: * Chrome reports CSP by exception when constructing [[Worker]] instance. * Firefox reports CSP errors when loading in first event: https://bugzilla.mozilla.org/show\_bug.cgi?id=1241888 * Firefox 62, Chrome 67 obeys | |
| Start worker "via blob" by first loading worker script code with [[fetch]], creating | |
| Start worker, loading it immediately from | |
| Waits for successful Web Worker start. Expects that worker script sends initial message. If first event is If first event is 'error', then it is assumed that worker failed to load and promise is rejected. (NOTE: The initial 'message' - if received - is immediately replayed using worker's We must resolve/reject promise at some time, so it is expected that any sane application will be able to load worker code in some amount of time. |