@loaders.gl/worker-utils 4.0.0-beta.7 → 4.0.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -7
- package/dist/lib/node/worker_threads.d.ts.map +1 -1
- package/dist/lib/node/worker_threads.js.map +1 -1
- package/dist/lib/worker-api/get-worker-url.d.ts.map +1 -1
- package/dist/lib/worker-api/get-worker-url.js.map +1 -1
- package/dist/lib/worker-farm/worker-thread.d.ts.map +1 -1
- package/dist/lib/worker-farm/worker-thread.js.map +1 -1
- package/package.json +2 -2
- package/src/lib/node/worker_threads.ts +1 -0
- package/src/lib/worker-api/get-worker-url.ts +1 -0
- package/src/lib/worker-farm/worker-thread.ts +1 -0
package/LICENSE
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
This software includes parts of PhiloGL (https://github.com/philogb/philogl)
|
|
4
|
-
under MIT license. PhiloGL parts Copyright © 2013 Sencha Labs.
|
|
1
|
+
loaders.gl is licensed under the MIT license
|
|
5
2
|
|
|
6
|
-
|
|
3
|
+
Copyright (c) vis.gl contributors
|
|
7
4
|
|
|
8
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -23,8 +20,12 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
23
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
21
|
THE SOFTWARE.
|
|
25
22
|
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
Copyright (c) 2015 Uber Technologies, Inc.
|
|
26
26
|
|
|
27
|
-
loaders.gl includes certain files from Cesium (https://github.com/AnalyticalGraphicsInc/cesium)
|
|
27
|
+
loaders.gl includes certain files from Cesium (https://github.com/AnalyticalGraphicsInc/cesium)
|
|
28
|
+
under the Apache 2 License (found in the submodule: modules/3d-tiles):)
|
|
28
29
|
|
|
29
30
|
Copyright 2011-2018 CesiumJS Contributors
|
|
30
31
|
|
|
@@ -38,4 +39,3 @@ distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
38
39
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
39
40
|
See the License for the specific language governing permissions and limitations under the License.
|
|
40
41
|
|
|
41
|
-
Cesium-derived code can be found in the submodule: modules/3d-tiles
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker_threads.d.ts","sourceRoot":"","sources":["../../../src/lib/node/worker_threads.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"worker_threads.d.ts","sourceRoot":"","sources":["../../../src/lib/node/worker_threads.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,aAAa,MAAM,gBAAgB,CAAC;AAChD,cAAc,gBAAgB,CAAC;AAC/B,eAAO,MAAM,UAAU,6BAAuB,CAAC;AAC/C,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC,MAAM,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker_threads.js","names":["WorkerThreads","NodeWorker","Worker"],"sources":["../../../src/lib/node/worker_threads.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport * as WorkerThreads from 'worker_threads';\nexport * from 'worker_threads';\nexport const NodeWorker = WorkerThreads.Worker;\nexport type NodeWorkerType = WorkerThreads.Worker;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"worker_threads.js","names":["WorkerThreads","NodeWorker","Worker"],"sources":["../../../src/lib/node/worker_threads.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport * as WorkerThreads from 'worker_threads';\nexport * from 'worker_threads';\nexport const NodeWorker = WorkerThreads.Worker;\nexport type NodeWorkerType = WorkerThreads.Worker;\n"],"mappings":"AAGA,OAAO,KAAKA,aAAa,MAAM,gBAAgB;AAC/C,cAAc,gBAAgB;AAC9B,OAAO,MAAMC,UAAU,GAAGD,aAAa,CAACE,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-worker-url.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-api/get-worker-url.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-worker-url.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-api/get-worker-url.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,YAAY,EAAE,aAAa,EAAC,MAAM,aAAa,CAAC;AAK7D;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAG1D;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAwCtF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-worker-url.js","names":["assert","isBrowser","VERSION","NPM_TAG","getWorkerName","worker","warning","version","name","getWorkerURL","options","arguments","length","undefined","workerOptions","id","workerFile","url","workerUrl","_workerType","module","versionTag"],"sources":["../../../src/lib/worker-api/get-worker-url.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {WorkerObject, WorkerOptions} from '../../types';\nimport {assert} from '../env-utils/assert';\nimport {isBrowser} from '../env-utils/globals';\nimport {VERSION, NPM_TAG} from '../env-utils/version';\n\n/**\n * Gets worker object's name (for debugging in Chrome thread inspector window)\n */\nexport function getWorkerName(worker: WorkerObject): string {\n const warning = worker.version !== VERSION ? ` (worker-utils@${VERSION})` : '';\n return `${worker.name}@${worker.version}${warning}`;\n}\n\n/**\n * Generate a worker URL based on worker object and options\n * @returns A URL to one of the following:\n * - a published worker on unpkg CDN\n * - a local test worker\n * - a URL provided by the user in options\n */\nexport function getWorkerURL(worker: WorkerObject, options: WorkerOptions = {}): string {\n const workerOptions = options[worker.id] || {};\n\n const workerFile = isBrowser ? `${worker.id}-worker.js` : `${worker.id}-worker-node.js`;\n\n let url = workerOptions.workerUrl;\n\n // HACK: Allow for non-nested workerUrl for the CompressionWorker.\n // For the compression worker, workerOptions is currently not nested correctly. For most loaders,\n // you'd have options within an object, i.e. `{mvt: {coordinates: ...}}` but the CompressionWorker\n // puts options at the top level, not within a `compression` key (its `id`). For this reason, the\n // above `workerOptions` will always be a string (i.e. `'gzip'`) for the CompressionWorker. To not\n // break backwards compatibility, we allow the CompressionWorker to have options at the top level.\n if (!url && worker.id === 'compression') {\n url = options.workerUrl;\n }\n\n // If URL is test, generate local loaders.gl url\n // @ts-ignore _workerType\n if (options._workerType === 'test') {\n url = `modules/${worker.module}/dist/${workerFile}`;\n }\n\n // If url override is not provided, generate a URL to published version on npm CDN unpkg.com\n if (!url) {\n // GENERATE\n let version = worker.version;\n // On master we need to load npm alpha releases published with the `beta` tag\n if (version === 'latest') {\n // throw new Error('latest worker version specified');\n version = NPM_TAG;\n }\n const versionTag = version ? `@${version}` : '';\n url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;\n }\n\n assert(url);\n\n // Allow user to override location\n return url;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-worker-url.js","names":["assert","isBrowser","VERSION","NPM_TAG","getWorkerName","worker","warning","version","name","getWorkerURL","options","arguments","length","undefined","workerOptions","id","workerFile","url","workerUrl","_workerType","module","versionTag"],"sources":["../../../src/lib/worker-api/get-worker-url.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {WorkerObject, WorkerOptions} from '../../types';\nimport {assert} from '../env-utils/assert';\nimport {isBrowser} from '../env-utils/globals';\nimport {VERSION, NPM_TAG} from '../env-utils/version';\n\n/**\n * Gets worker object's name (for debugging in Chrome thread inspector window)\n */\nexport function getWorkerName(worker: WorkerObject): string {\n const warning = worker.version !== VERSION ? ` (worker-utils@${VERSION})` : '';\n return `${worker.name}@${worker.version}${warning}`;\n}\n\n/**\n * Generate a worker URL based on worker object and options\n * @returns A URL to one of the following:\n * - a published worker on unpkg CDN\n * - a local test worker\n * - a URL provided by the user in options\n */\nexport function getWorkerURL(worker: WorkerObject, options: WorkerOptions = {}): string {\n const workerOptions = options[worker.id] || {};\n\n const workerFile = isBrowser ? `${worker.id}-worker.js` : `${worker.id}-worker-node.js`;\n\n let url = workerOptions.workerUrl;\n\n // HACK: Allow for non-nested workerUrl for the CompressionWorker.\n // For the compression worker, workerOptions is currently not nested correctly. For most loaders,\n // you'd have options within an object, i.e. `{mvt: {coordinates: ...}}` but the CompressionWorker\n // puts options at the top level, not within a `compression` key (its `id`). For this reason, the\n // above `workerOptions` will always be a string (i.e. `'gzip'`) for the CompressionWorker. To not\n // break backwards compatibility, we allow the CompressionWorker to have options at the top level.\n if (!url && worker.id === 'compression') {\n url = options.workerUrl;\n }\n\n // If URL is test, generate local loaders.gl url\n // @ts-ignore _workerType\n if (options._workerType === 'test') {\n url = `modules/${worker.module}/dist/${workerFile}`;\n }\n\n // If url override is not provided, generate a URL to published version on npm CDN unpkg.com\n if (!url) {\n // GENERATE\n let version = worker.version;\n // On master we need to load npm alpha releases published with the `beta` tag\n if (version === 'latest') {\n // throw new Error('latest worker version specified');\n version = NPM_TAG;\n }\n const versionTag = version ? `@${version}` : '';\n url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;\n }\n\n assert(url);\n\n // Allow user to override location\n return url;\n}\n"],"mappings":"SAIQA,MAAM;AAAA,SACNC,SAAS;AAAA,SACTC,OAAO,EAAEC,OAAO;AAKxB,OAAO,SAASC,aAAaA,CAACC,MAAoB,EAAU;EAC1D,MAAMC,OAAO,GAAGD,MAAM,CAACE,OAAO,KAAKL,OAAO,GAAI,kBAAiBA,OAAQ,GAAE,GAAG,EAAE;EAC9E,OAAQ,GAAEG,MAAM,CAACG,IAAK,IAAGH,MAAM,CAACE,OAAQ,GAAED,OAAQ,EAAC;AACrD;AASA,OAAO,SAASG,YAAYA,CAACJ,MAAoB,EAAuC;EAAA,IAArCK,OAAsB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAC5E,MAAMG,aAAa,GAAGJ,OAAO,CAACL,MAAM,CAACU,EAAE,CAAC,IAAI,CAAC,CAAC;EAE9C,MAAMC,UAAU,GAAGf,SAAS,GAAI,GAAEI,MAAM,CAACU,EAAG,YAAW,GAAI,GAAEV,MAAM,CAACU,EAAG,iBAAgB;EAEvF,IAAIE,GAAG,GAAGH,aAAa,CAACI,SAAS;EAQjC,IAAI,CAACD,GAAG,IAAIZ,MAAM,CAACU,EAAE,KAAK,aAAa,EAAE;IACvCE,GAAG,GAAGP,OAAO,CAACQ,SAAS;EACzB;EAIA,IAAIR,OAAO,CAACS,WAAW,KAAK,MAAM,EAAE;IAClCF,GAAG,GAAI,WAAUZ,MAAM,CAACe,MAAO,SAAQJ,UAAW,EAAC;EACrD;EAGA,IAAI,CAACC,GAAG,EAAE;IAER,IAAIV,OAAO,GAAGF,MAAM,CAACE,OAAO;IAE5B,IAAIA,OAAO,KAAK,QAAQ,EAAE;MAExBA,OAAO,GAAGJ,OAAO;IACnB;IACA,MAAMkB,UAAU,GAAGd,OAAO,GAAI,IAAGA,OAAQ,EAAC,GAAG,EAAE;IAC/CU,GAAG,GAAI,iCAAgCZ,MAAM,CAACe,MAAO,GAAEC,UAAW,SAAQL,UAAW,EAAC;EACxF;EAEAhB,MAAM,CAACiB,GAAG,CAAC;EAGX,OAAOA,GAAG;AACZ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-thread.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-farm/worker-thread.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"worker-thread.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-farm/worker-thread.ts"],"names":[],"mappings":"AAGA,OAAO,EAAa,cAAc,EAAC,MAAM,wBAAwB,CAAC;AAQlE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,UAAU,EAAE,OAAO,CAAS;IAC5B,MAAM,EAAE,MAAM,GAAG,cAAc,CAAC;IAChC,SAAS,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;IAClC,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAEhC,OAAO,CAAC,YAAY,CAAc;IAElC,uDAAuD;IACvD,MAAM,CAAC,WAAW,IAAI,OAAO;gBAOjB,KAAK,EAAE,iBAAiB;IAYpC;;;OAGG;IACH,OAAO,IAAI,IAAI;IAOf,IAAI,SAAS,YAEZ;IAED;;;;OAIG;IACH,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,YAAY,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI;IAQlD;;;OAGG;IACH,uBAAuB,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK;IAiBjD;;OAEG;IACH,oBAAoB,IAAI,MAAM;IAsB9B;;;OAGG;IACH,iBAAiB,IAAI,cAAc;CA0BpC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-thread.js","names":["NodeWorker","isBrowser","assert","getLoadableWorkerURL","getTransferList","NOOP","WorkerThread","isSupported","Worker","constructor","props","name","source","url","terminated","worker","onMessage","onError","_loadableURL","error","console","log","_createBrowserWorker","_createNodeWorker","destroy","terminate","isRunning","Boolean","postMessage","data","transferList","_getErrorFromErrorEvent","event","message","lineno","colno","Error","onmessage","onerror","onmessageerror","absolute","includes","startsWith","eval","on","code"],"sources":["../../../src/lib/worker-farm/worker-thread.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {NodeWorker, NodeWorkerType} from '../node/worker_threads';\nimport {isBrowser} from '../env-utils/globals';\nimport {assert} from '../env-utils/assert';\nimport {getLoadableWorkerURL} from '../worker-utils/get-loadable-worker-url';\nimport {getTransferList} from '../worker-utils/get-transfer-list';\n\nconst NOOP = () => {};\n\nexport type WorkerThreadProps = {\n name: string;\n source?: string;\n url?: string;\n};\n\n/**\n * Represents one worker thread\n */\nexport default class WorkerThread {\n readonly name: string;\n readonly source: string | undefined;\n readonly url: string | undefined;\n terminated: boolean = false;\n worker: Worker | NodeWorkerType;\n onMessage: (message: any) => void;\n onError: (error: Error) => void;\n\n private _loadableURL: string = '';\n\n /** Checks if workers are supported on this platform */\n static isSupported(): boolean {\n return (\n (typeof Worker !== 'undefined' && isBrowser) ||\n (typeof NodeWorker !== 'undefined' && !isBrowser)\n );\n }\n\n constructor(props: WorkerThreadProps) {\n const {name, source, url} = props;\n assert(source || url); // Either source or url must be defined\n this.name = name;\n this.source = source;\n this.url = url;\n this.onMessage = NOOP;\n this.onError = (error) => console.log(error); // eslint-disable-line\n\n this.worker = isBrowser ? this._createBrowserWorker() : this._createNodeWorker();\n }\n\n /**\n * Terminate this worker thread\n * @note Can free up significant memory\n */\n destroy(): void {\n this.onMessage = NOOP;\n this.onError = NOOP;\n this.worker.terminate(); // eslint-disable-line @typescript-eslint/no-floating-promises\n this.terminated = true;\n }\n\n get isRunning() {\n return Boolean(this.onMessage);\n }\n\n /**\n * Send a message to this worker thread\n * @param data any data structure, ideally consisting mostly of transferrable objects\n * @param transferList If not supplied, calculated automatically by traversing data\n */\n postMessage(data: any, transferList?: any[]): void {\n transferList = transferList || getTransferList(data);\n // @ts-ignore\n this.worker.postMessage(data, transferList);\n }\n\n // PRIVATE\n\n /**\n * Generate a standard Error from an ErrorEvent\n * @param event\n */\n _getErrorFromErrorEvent(event: ErrorEvent): Error {\n // Note Error object does not have the expected fields if loading failed completely\n // https://developer.mozilla.org/en-US/docs/Web/API/Worker#Event_handlers\n // https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent\n let message = 'Failed to load ';\n message += `worker ${this.name} from ${this.url}. `;\n if (event.message) {\n message += `${event.message} in `;\n }\n // const hasFilename = event.filename && !event.filename.startsWith('blob:');\n // message += hasFilename ? event.filename : this.source.slice(0, 100);\n if (event.lineno) {\n message += `:${event.lineno}:${event.colno}`;\n }\n return new Error(message);\n }\n\n /**\n * Creates a worker thread on the browser\n */\n _createBrowserWorker(): Worker {\n this._loadableURL = getLoadableWorkerURL({source: this.source, url: this.url});\n const worker = new Worker(this._loadableURL, {name: this.name});\n\n worker.onmessage = (event) => {\n if (!event.data) {\n this.onError(new Error('No data received'));\n } else {\n this.onMessage(event.data);\n }\n };\n // This callback represents an uncaught exception in the worker thread\n worker.onerror = (error: ErrorEvent): void => {\n this.onError(this._getErrorFromErrorEvent(error));\n this.terminated = true;\n };\n // TODO - not clear when this would be called, for now just log in case it happens\n worker.onmessageerror = (event) => console.error(event); // eslint-disable-line\n\n return worker;\n }\n\n /**\n * Creates a worker thread in node.js\n * @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool\n */\n _createNodeWorker(): NodeWorkerType {\n let worker: NodeWorkerType;\n if (this.url) {\n // Make sure relative URLs start with './'\n const absolute = this.url.includes(':/') || this.url.startsWith('/');\n const url = absolute ? this.url : `./${this.url}`;\n // console.log('Starting work from', url);\n worker = new NodeWorker(url, {eval: false});\n } else if (this.source) {\n worker = new NodeWorker(this.source, {eval: true});\n } else {\n throw new Error('no worker');\n }\n worker.on('message', (data) => {\n // console.error('message', data);\n this.onMessage(data);\n });\n worker.on('error', (error) => {\n // console.error('error', error);\n this.onError(error);\n });\n worker.on('exit', (code) => {\n // console.error('exit', code);\n });\n return worker;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"worker-thread.js","names":["NodeWorker","isBrowser","assert","getLoadableWorkerURL","getTransferList","NOOP","WorkerThread","isSupported","Worker","constructor","props","name","source","url","terminated","worker","onMessage","onError","_loadableURL","error","console","log","_createBrowserWorker","_createNodeWorker","destroy","terminate","isRunning","Boolean","postMessage","data","transferList","_getErrorFromErrorEvent","event","message","lineno","colno","Error","onmessage","onerror","onmessageerror","absolute","includes","startsWith","eval","on","code"],"sources":["../../../src/lib/worker-farm/worker-thread.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {NodeWorker, NodeWorkerType} from '../node/worker_threads';\nimport {isBrowser} from '../env-utils/globals';\nimport {assert} from '../env-utils/assert';\nimport {getLoadableWorkerURL} from '../worker-utils/get-loadable-worker-url';\nimport {getTransferList} from '../worker-utils/get-transfer-list';\n\nconst NOOP = () => {};\n\nexport type WorkerThreadProps = {\n name: string;\n source?: string;\n url?: string;\n};\n\n/**\n * Represents one worker thread\n */\nexport default class WorkerThread {\n readonly name: string;\n readonly source: string | undefined;\n readonly url: string | undefined;\n terminated: boolean = false;\n worker: Worker | NodeWorkerType;\n onMessage: (message: any) => void;\n onError: (error: Error) => void;\n\n private _loadableURL: string = '';\n\n /** Checks if workers are supported on this platform */\n static isSupported(): boolean {\n return (\n (typeof Worker !== 'undefined' && isBrowser) ||\n (typeof NodeWorker !== 'undefined' && !isBrowser)\n );\n }\n\n constructor(props: WorkerThreadProps) {\n const {name, source, url} = props;\n assert(source || url); // Either source or url must be defined\n this.name = name;\n this.source = source;\n this.url = url;\n this.onMessage = NOOP;\n this.onError = (error) => console.log(error); // eslint-disable-line\n\n this.worker = isBrowser ? this._createBrowserWorker() : this._createNodeWorker();\n }\n\n /**\n * Terminate this worker thread\n * @note Can free up significant memory\n */\n destroy(): void {\n this.onMessage = NOOP;\n this.onError = NOOP;\n this.worker.terminate(); // eslint-disable-line @typescript-eslint/no-floating-promises\n this.terminated = true;\n }\n\n get isRunning() {\n return Boolean(this.onMessage);\n }\n\n /**\n * Send a message to this worker thread\n * @param data any data structure, ideally consisting mostly of transferrable objects\n * @param transferList If not supplied, calculated automatically by traversing data\n */\n postMessage(data: any, transferList?: any[]): void {\n transferList = transferList || getTransferList(data);\n // @ts-ignore\n this.worker.postMessage(data, transferList);\n }\n\n // PRIVATE\n\n /**\n * Generate a standard Error from an ErrorEvent\n * @param event\n */\n _getErrorFromErrorEvent(event: ErrorEvent): Error {\n // Note Error object does not have the expected fields if loading failed completely\n // https://developer.mozilla.org/en-US/docs/Web/API/Worker#Event_handlers\n // https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent\n let message = 'Failed to load ';\n message += `worker ${this.name} from ${this.url}. `;\n if (event.message) {\n message += `${event.message} in `;\n }\n // const hasFilename = event.filename && !event.filename.startsWith('blob:');\n // message += hasFilename ? event.filename : this.source.slice(0, 100);\n if (event.lineno) {\n message += `:${event.lineno}:${event.colno}`;\n }\n return new Error(message);\n }\n\n /**\n * Creates a worker thread on the browser\n */\n _createBrowserWorker(): Worker {\n this._loadableURL = getLoadableWorkerURL({source: this.source, url: this.url});\n const worker = new Worker(this._loadableURL, {name: this.name});\n\n worker.onmessage = (event) => {\n if (!event.data) {\n this.onError(new Error('No data received'));\n } else {\n this.onMessage(event.data);\n }\n };\n // This callback represents an uncaught exception in the worker thread\n worker.onerror = (error: ErrorEvent): void => {\n this.onError(this._getErrorFromErrorEvent(error));\n this.terminated = true;\n };\n // TODO - not clear when this would be called, for now just log in case it happens\n worker.onmessageerror = (event) => console.error(event); // eslint-disable-line\n\n return worker;\n }\n\n /**\n * Creates a worker thread in node.js\n * @todo https://nodejs.org/api/async_hooks.html#async-resource-worker-pool\n */\n _createNodeWorker(): NodeWorkerType {\n let worker: NodeWorkerType;\n if (this.url) {\n // Make sure relative URLs start with './'\n const absolute = this.url.includes(':/') || this.url.startsWith('/');\n const url = absolute ? this.url : `./${this.url}`;\n // console.log('Starting work from', url);\n worker = new NodeWorker(url, {eval: false});\n } else if (this.source) {\n worker = new NodeWorker(this.source, {eval: true});\n } else {\n throw new Error('no worker');\n }\n worker.on('message', (data) => {\n // console.error('message', data);\n this.onMessage(data);\n });\n worker.on('error', (error) => {\n // console.error('error', error);\n this.onError(error);\n });\n worker.on('exit', (code) => {\n // console.error('exit', code);\n });\n return worker;\n }\n}\n"],"mappings":"SAGQA,UAAU;AAAA,SACVC,SAAS;AAAA,SACTC,MAAM;AAAA,SACNC,oBAAoB;AAAA,SACpBC,eAAe;AAEvB,MAAMC,IAAI,GAAGA,CAAA,KAAM,CAAC,CAAC;AAWrB,eAAe,MAAMC,YAAY,CAAC;EAYhC,OAAOC,WAAWA,CAAA,EAAY;IAC5B,OACG,OAAOC,MAAM,KAAK,WAAW,IAAIP,SAAS,IAC1C,OAAOD,UAAU,KAAK,WAAW,IAAI,CAACC,SAAU;EAErD;EAEAQ,WAAWA,CAACC,KAAwB,EAAE;IAAA,KAlB7BC,IAAI;IAAA,KACJC,MAAM;IAAA,KACNC,GAAG;IAAA,KACZC,UAAU,GAAY,KAAK;IAAA,KAC3BC,MAAM;IAAA,KACNC,SAAS;IAAA,KACTC,OAAO;IAAA,KAECC,YAAY,GAAW,EAAE;IAW/B,MAAM;MAACP,IAAI;MAAEC,MAAM;MAAEC;IAAG,CAAC,GAAGH,KAAK;IACjCR,MAAM,CAACU,MAAM,IAAIC,GAAG,CAAC;IACrB,IAAI,CAACF,IAAI,GAAGA,IAAI;IAChB,IAAI,CAACC,MAAM,GAAGA,MAAM;IACpB,IAAI,CAACC,GAAG,GAAGA,GAAG;IACd,IAAI,CAACG,SAAS,GAAGX,IAAI;IACrB,IAAI,CAACY,OAAO,GAAIE,KAAK,IAAKC,OAAO,CAACC,GAAG,CAACF,KAAK,CAAC;IAE5C,IAAI,CAACJ,MAAM,GAAGd,SAAS,GAAG,IAAI,CAACqB,oBAAoB,CAAC,CAAC,GAAG,IAAI,CAACC,iBAAiB,CAAC,CAAC;EAClF;EAMAC,OAAOA,CAAA,EAAS;IACd,IAAI,CAACR,SAA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IAAI,CAACF,OAAO,CAACE,KAAK,CAAC;IACrB,CAAC,CAAC;IACFJ,MAAM,CAAC6B,EAAE,CAAC,MAAM,EAAGC,IAAI,IAAK,CAE5B,CAAC,CAAC;IACF,OAAO9B,MAAM;EACf;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/worker-utils",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.8",
|
|
4
4
|
"description": "Utilities for running tasks on worker threads",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@babel/runtime": "^7.3.1"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "ec3d1747b4c01c52a235455d6462680e711b4e19"
|
|
56
56
|
}
|