@loaders.gl/worker-utils 3.0.13 → 3.0.14
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/dist/es5/index.js +19 -19
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/async-queue/async-queue.js +76 -62
- package/dist/es5/lib/async-queue/async-queue.js.map +1 -1
- package/dist/es5/lib/env-utils/globals.js +15 -10
- package/dist/es5/lib/env-utils/globals.js.map +1 -1
- package/dist/es5/lib/env-utils/version.js +3 -3
- package/dist/es5/lib/env-utils/version.js.map +1 -1
- package/dist/es5/lib/library-utils/library-utils.js +127 -29
- package/dist/es5/lib/library-utils/library-utils.js.map +1 -1
- package/dist/es5/lib/node/require-utils.node.js +65 -20
- package/dist/es5/lib/node/require-utils.node.js.map +1 -1
- package/dist/es5/lib/process-utils/child-process-proxy.js +199 -90
- package/dist/es5/lib/process-utils/child-process-proxy.js.map +1 -1
- package/dist/es5/lib/process-utils/process-utils.js +9 -8
- package/dist/es5/lib/process-utils/process-utils.js.map +1 -1
- package/dist/es5/lib/worker-api/create-worker.js +162 -52
- package/dist/es5/lib/worker-api/create-worker.js.map +1 -1
- package/dist/es5/lib/worker-api/get-worker-url.js +10 -9
- package/dist/es5/lib/worker-api/get-worker-url.js.map +1 -1
- package/dist/es5/lib/worker-api/process-on-worker.js +130 -59
- package/dist/es5/lib/worker-api/process-on-worker.js.map +1 -1
- package/dist/es5/lib/worker-api/validate-worker-version.js +4 -3
- package/dist/es5/lib/worker-api/validate-worker-version.js.map +1 -1
- package/dist/es5/lib/worker-farm/worker-body.js +58 -46
- package/dist/es5/lib/worker-farm/worker-body.js.map +1 -1
- package/dist/es5/lib/worker-farm/worker-farm.js +99 -60
- package/dist/es5/lib/worker-farm/worker-farm.js.map +1 -1
- package/dist/es5/lib/worker-farm/worker-job.js +40 -28
- package/dist/es5/lib/worker-farm/worker-job.js.map +1 -1
- package/dist/es5/lib/worker-farm/worker-pool.js +204 -108
- package/dist/es5/lib/worker-farm/worker-pool.js.map +1 -1
- package/dist/es5/lib/worker-farm/worker-thread.js +85 -67
- package/dist/es5/lib/worker-farm/worker-thread.js.map +1 -1
- package/dist/es5/lib/worker-utils/get-loadable-worker-url.js +4 -4
- package/dist/es5/lib/worker-utils/get-loadable-worker-url.js.map +1 -1
- package/dist/es5/lib/worker-utils/get-transfer-list.js +10 -4
- package/dist/es5/lib/worker-utils/get-transfer-list.js.map +1 -1
- package/dist/es5/lib/worker-utils/remove-nontransferable-options.js +7 -3
- package/dist/es5/lib/worker-utils/remove-nontransferable-options.js.map +1 -1
- package/dist/es5/workers/null-worker.js +26 -3
- package/dist/es5/workers/null-worker.js.map +1 -1
- package/dist/esm/lib/env-utils/version.js +2 -2
- package/dist/esm/lib/library-utils/library-utils.js +1 -1
- package/dist/esm/lib/worker-api/get-worker-url.js +1 -1
- package/dist/null-worker.js +3 -3
- package/dist/null-worker.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/worker-utils/get-loadable-worker-url.ts"],"names":["workerURLCache","Map","getLoadableWorkerURL","props","source","url","workerURL","get","getLoadableWorkerURLFromURL","set","getLoadableWorkerURLFromSource","startsWith","workerSource","buildScriptSource","blob","Blob","type","URL","createObjectURL","workerUrl"],"mappings":";;;;;;;AAAA;;AAEA,
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/worker-utils/get-loadable-worker-url.ts"],"names":["workerURLCache","Map","getLoadableWorkerURL","props","source","url","workerURL","get","getLoadableWorkerURLFromURL","set","getLoadableWorkerURLFromSource","startsWith","workerSource","buildScriptSource","blob","Blob","type","URL","createObjectURL","workerUrl"],"mappings":";;;;;;;AAAA;;AAEA,IAAMA,cAAc,GAAG,IAAIC,GAAJ,EAAvB;;AAWO,SAASC,oBAAT,CAA8BC,KAA9B,EAAsE;AAC3E,sBAAQA,KAAK,CAACC,MAAN,IAAgB,CAACD,KAAK,CAACE,GAAxB,IAAiC,CAACF,KAAK,CAACC,MAAP,IAAiBD,KAAK,CAACE,GAA/D;AAEA,MAAIC,SAAS,GAAGN,cAAc,CAACO,GAAf,CAAmBJ,KAAK,CAACC,MAAN,IAAgBD,KAAK,CAACE,GAAzC,CAAhB;;AACA,MAAI,CAACC,SAAL,EAAgB;AAEd,QAAIH,KAAK,CAACE,GAAV,EAAe;AACbC,MAAAA,SAAS,GAAGE,2BAA2B,CAACL,KAAK,CAACE,GAAP,CAAvC;AACAL,MAAAA,cAAc,CAACS,GAAf,CAAmBN,KAAK,CAACE,GAAzB,EAA8BC,SAA9B;AACD;;AAED,QAAIH,KAAK,CAACC,MAAV,EAAkB;AAChBE,MAAAA,SAAS,GAAGI,8BAA8B,CAACP,KAAK,CAACC,MAAP,CAA1C;AACAJ,MAAAA,cAAc,CAACS,GAAf,CAAmBN,KAAK,CAACC,MAAzB,EAAiCE,SAAjC;AACD;AACF;;AAED,sBAAOA,SAAP;AACA,SAAOA,SAAP;AACD;;AAOD,SAASE,2BAAT,CAAqCH,GAArC,EAA0D;AAExD,MAAI,CAACA,GAAG,CAACM,UAAJ,CAAe,MAAf,CAAL,EAA6B;AAC3B,WAAON,GAAP;AACD;;AAGD,MAAMO,YAAY,GAAGC,iBAAiB,CAACR,GAAD,CAAtC;AACA,SAAOK,8BAA8B,CAACE,YAAD,CAArC;AACD;;AAOD,SAASF,8BAAT,CAAwCE,YAAxC,EAAsE;AAGpE,MAAME,IAAI,GAAG,IAAIC,IAAJ,CAAS,CAACH,YAAD,CAAT,EAAyB;AAACI,IAAAA,IAAI,EAAE;AAAP,GAAzB,CAAb;AACA,SAAOC,GAAG,CAACC,eAAJ,CAAoBJ,IAApB,CAAP;AACD;;AAUD,SAASD,iBAAT,CAA2BM,SAA3B,EAAsD;AACpD,2CAEiBA,SAFjB;AAOD","sourcesContent":["import {assert} from '../env-utils/assert';\n\nconst workerURLCache = new Map();\n\n/**\n * Creates a loadable URL from worker source or URL\n * that can be used to create `Worker` instances.\n * Due to CORS issues it may be necessary to wrap a URL in a small importScripts\n * @param props\n * @param props.source Worker source\n * @param props.url Worker URL\n * @returns loadable url\n */\nexport function getLoadableWorkerURL(props: {source?: string; url?: string}) {\n assert((props.source && !props.url) || (!props.source && props.url)); // Either source or url must be defined\n\n let workerURL = workerURLCache.get(props.source || props.url);\n if (!workerURL) {\n // Differentiate worker urls from worker source code\n if (props.url) {\n workerURL = getLoadableWorkerURLFromURL(props.url);\n workerURLCache.set(props.url, workerURL);\n }\n\n if (props.source) {\n workerURL = getLoadableWorkerURLFromSource(props.source);\n workerURLCache.set(props.source, workerURL);\n }\n }\n\n assert(workerURL);\n return workerURL;\n}\n\n/**\n * Build a loadable worker URL from worker URL\n * @param url\n * @returns loadable URL\n */\nfunction getLoadableWorkerURLFromURL(url: string): string {\n // A local script url, we can use it to initialize a Worker directly\n if (!url.startsWith('http')) {\n return url;\n }\n\n // A remote script, we need to use `importScripts` to load from different origin\n const workerSource = buildScriptSource(url);\n return getLoadableWorkerURLFromSource(workerSource);\n}\n\n/**\n * Build a loadable worker URL from worker source\n * @param workerSource\n * @returns loadable url\n */\nfunction getLoadableWorkerURLFromSource(workerSource: string): string {\n // NOTE: webworkify was previously used\n // const blob = webworkify(workerSource, {bare: true});\n const blob = new Blob([workerSource], {type: 'application/javascript'});\n return URL.createObjectURL(blob);\n}\n\n/**\n * Per spec, worker cannot be initialized with a script from a different origin\n * However a local worker script can still import scripts from other origins,\n * so we simply build a wrapper script.\n *\n * @param workerUrl\n * @returns source\n */\nfunction buildScriptSource(workerUrl: string): string {\n return `\\\ntry {\n importScripts('${workerUrl}');\n} catch (error) {\n console.error(error);\n throw error;\n}`;\n}\n"],"file":"get-loadable-worker-url.js"}
|
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
8
|
exports.getTransferList = getTransferList;
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
+
|
|
12
|
+
function getTransferList(object) {
|
|
13
|
+
var recursive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
14
|
+
var transfers = arguments.length > 2 ? arguments[2] : undefined;
|
|
15
|
+
var transfersSet = transfers || new Set();
|
|
10
16
|
|
|
11
17
|
if (!object) {} else if (isTransferable(object)) {
|
|
12
18
|
transfersSet.add(object);
|
|
13
19
|
} else if (isTransferable(object.buffer)) {
|
|
14
20
|
transfersSet.add(object.buffer);
|
|
15
|
-
} else if (ArrayBuffer.isView(object)) {} else if (recursive &&
|
|
16
|
-
for (
|
|
21
|
+
} else if (ArrayBuffer.isView(object)) {} else if (recursive && (0, _typeof2.default)(object) === 'object') {
|
|
22
|
+
for (var key in object) {
|
|
17
23
|
getTransferList(object[key], recursive, transfersSet);
|
|
18
24
|
}
|
|
19
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/worker-utils/get-transfer-list.ts"],"names":["getTransferList","object","recursive","transfers","transfersSet","Set","isTransferable","add","buffer","ArrayBuffer","isView","key","undefined","Array","from","MessagePort","ImageBitmap","OffscreenCanvas"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/worker-utils/get-transfer-list.ts"],"names":["getTransferList","object","recursive","transfers","transfersSet","Set","isTransferable","add","buffer","ArrayBuffer","isView","key","undefined","Array","from","MessagePort","ImageBitmap","OffscreenCanvas"],"mappings":";;;;;;;;;;;AAWO,SAASA,eAAT,CACLC,MADK,EAIW;AAAA,MAFhBC,SAEgB,uEAFK,IAEL;AAAA,MADhBC,SACgB;AAEhB,MAAMC,YAAY,GAAGD,SAAS,IAAI,IAAIE,GAAJ,EAAlC;;AAEA,MAAI,CAACJ,MAAL,EAAa,CAEZ,CAFD,MAEO,IAAIK,cAAc,CAACL,MAAD,CAAlB,EAA4B;AACjCG,IAAAA,YAAY,CAACG,GAAb,CAAiBN,MAAjB;AACD,GAFM,MAEA,IAAIK,cAAc,CAACL,MAAM,CAACO,MAAR,CAAlB,EAAmC;AAExCJ,IAAAA,YAAY,CAACG,GAAb,CAAiBN,MAAM,CAACO,MAAxB;AACD,GAHM,MAGA,IAAIC,WAAW,CAACC,MAAZ,CAAmBT,MAAnB,CAAJ,EAAgC,CAGtC,CAHM,MAGA,IAAIC,SAAS,IAAI,sBAAOD,MAAP,MAAkB,QAAnC,EAA6C;AAClD,SAAK,IAAMU,GAAX,IAAkBV,MAAlB,EAA0B;AAExBD,MAAAA,eAAe,CAACC,MAAM,CAACU,GAAD,CAAP,EAAcT,SAAd,EAAyBE,YAAzB,CAAf;AACD;AACF;;AAID,SAAOD,SAAS,KAAKS,SAAd,GAA0BC,KAAK,CAACC,IAAN,CAAWV,YAAX,CAA1B,GAAqD,EAA5D;AACD;;AAGD,SAASE,cAAT,CAAwBL,MAAxB,EAAgC;AAC9B,MAAI,CAACA,MAAL,EAAa;AACX,WAAO,KAAP;AACD;;AACD,MAAIA,MAAM,YAAYQ,WAAtB,EAAmC;AACjC,WAAO,IAAP;AACD;;AACD,MAAI,OAAOM,WAAP,KAAuB,WAAvB,IAAsCd,MAAM,YAAYc,WAA5D,EAAyE;AACvE,WAAO,IAAP;AACD;;AACD,MAAI,OAAOC,WAAP,KAAuB,WAAvB,IAAsCf,MAAM,YAAYe,WAA5D,EAAyE;AACvE,WAAO,IAAP;AACD;;AAED,MAAI,OAAOC,eAAP,KAA2B,WAA3B,IAA0ChB,MAAM,YAAYgB,eAAhE,EAAiF;AAC/E,WAAO,IAAP;AACD;;AACD,SAAO,KAAP;AACD","sourcesContent":["// NOTE - there is a copy of this function is both in core and loader-utils\n// core does not need all the utils in loader-utils, just this one.\n\n/**\n * Returns an array of Transferrable objects that can be used with postMessage\n * https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage\n * @param object data to be sent via postMessage\n * @param recursive - not for application use\n * @param transfers - not for application use\n * @returns a transfer list that can be passed to postMessage\n */\nexport function getTransferList(\n object: any,\n recursive: boolean = true,\n transfers?: Set<any>\n): Transferable[] {\n // Make sure that items in the transfer list is unique\n const transfersSet = transfers || new Set();\n\n if (!object) {\n // ignore\n } else if (isTransferable(object)) {\n transfersSet.add(object);\n } else if (isTransferable(object.buffer)) {\n // Typed array\n transfersSet.add(object.buffer);\n } else if (ArrayBuffer.isView(object)) {\n // object is a TypeArray viewing into a SharedArrayBuffer (not transferable)\n // Do not iterate through the content in this case\n } else if (recursive && typeof object === 'object') {\n for (const key in object) {\n // Avoid perf hit - only go one level deep\n getTransferList(object[key], recursive, transfersSet);\n }\n }\n\n // If transfers is defined, is internal recursive call\n // Otherwise it's called by the user\n return transfers === undefined ? Array.from(transfersSet) : [];\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/API/Transferable\nfunction isTransferable(object) {\n if (!object) {\n return false;\n }\n if (object instanceof ArrayBuffer) {\n return true;\n }\n if (typeof MessagePort !== 'undefined' && object instanceof MessagePort) {\n return true;\n }\n if (typeof ImageBitmap !== 'undefined' && object instanceof ImageBitmap) {\n return true;\n }\n // @ts-ignore\n if (typeof OffscreenCanvas !== 'undefined' && object instanceof OffscreenCanvas) {\n return true;\n }\n return false;\n}\n"],"file":"get-transfer-list.js"}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
8
|
exports.removeNontransferableOptions = removeNontransferableOptions;
|
|
7
9
|
|
|
10
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
11
|
+
|
|
8
12
|
function removeNontransferableOptions(object) {
|
|
9
13
|
return JSON.parse(stringifyJSON(object));
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
function stringifyJSON(v) {
|
|
13
|
-
|
|
14
|
-
return JSON.stringify(v, (key, value)
|
|
15
|
-
if (
|
|
17
|
+
var cache = new Set();
|
|
18
|
+
return JSON.stringify(v, function (key, value) {
|
|
19
|
+
if ((0, _typeof2.default)(value) === 'object' && value !== null) {
|
|
16
20
|
if (cache.has(value)) {
|
|
17
21
|
try {
|
|
18
22
|
return JSON.parse(JSON.stringify(value));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/lib/worker-utils/remove-nontransferable-options.ts"],"names":["removeNontransferableOptions","object","JSON","parse","stringifyJSON","v","cache","Set","stringify","key","value","has","err","undefined","add"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/lib/worker-utils/remove-nontransferable-options.ts"],"names":["removeNontransferableOptions","object","JSON","parse","stringifyJSON","v","cache","Set","stringify","key","value","has","err","undefined","add"],"mappings":";;;;;;;;;;;AAIO,SAASA,4BAAT,CAAsCC,MAAtC,EAA8D;AAInE,SAAOC,IAAI,CAACC,KAAL,CAAWC,aAAa,CAACH,MAAD,CAAxB,CAAP;AACD;;AAED,SAASG,aAAT,CAAuBC,CAAvB,EAA0B;AACxB,MAAMC,KAAK,GAAG,IAAIC,GAAJ,EAAd;AACA,SAAOL,IAAI,CAACM,SAAL,CAAeH,CAAf,EAAkB,UAACI,GAAD,EAAMC,KAAN,EAAgB;AACvC,QAAI,sBAAOA,KAAP,MAAiB,QAAjB,IAA6BA,KAAK,KAAK,IAA3C,EAAiD;AAC/C,UAAIJ,KAAK,CAACK,GAAN,CAAUD,KAAV,CAAJ,EAAsB;AAEpB,YAAI;AAEF,iBAAOR,IAAI,CAACC,KAAL,CAAWD,IAAI,CAACM,SAAL,CAAeE,KAAf,CAAX,CAAP;AACD,SAHD,CAGE,OAAOE,GAAP,EAAY;AAEZ,iBAAOC,SAAP;AACD;AACF;;AAEDP,MAAAA,KAAK,CAACQ,GAAN,CAAUJ,KAAV;AACD;;AACD,WAAOA,KAAP;AACD,GAhBM,CAAP;AAiBD","sourcesContent":["/**\n * Safely stringify JSON (drop non serializable values like functions and regexps)\n * @param value\n */\nexport function removeNontransferableOptions(object: object): object {\n // options.log object contains functions which cannot be transferred\n // TODO - decide how to handle logging on workers\n // TODO - warn if options stringification is long\n return JSON.parse(stringifyJSON(object));\n}\n\nfunction stringifyJSON(v) {\n const cache = new Set();\n return JSON.stringify(v, (key, value) => {\n if (typeof value === 'object' && value !== null) {\n if (cache.has(value)) {\n // Circular reference found\n try {\n // If this value does not reference a parent it can be deduped\n return JSON.parse(JSON.stringify(value));\n } catch (err) {\n // discard key if value cannot be deduped\n return undefined;\n }\n }\n // Store value in our set\n cache.add(value);\n }\n return value;\n });\n}\n"],"file":"remove-nontransferable-options.js"}
|
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
6
|
+
|
|
7
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
8
|
+
|
|
3
9
|
var _createWorker = require("../lib/worker-api/create-worker");
|
|
4
10
|
|
|
5
|
-
(0, _createWorker.createWorker)(
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
(0, _createWorker.createWorker)(function () {
|
|
12
|
+
var _ref = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(data) {
|
|
13
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
14
|
+
while (1) {
|
|
15
|
+
switch (_context.prev = _context.next) {
|
|
16
|
+
case 0:
|
|
17
|
+
return _context.abrupt("return", data);
|
|
18
|
+
|
|
19
|
+
case 1:
|
|
20
|
+
case "end":
|
|
21
|
+
return _context.stop();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}, _callee);
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
return function (_x) {
|
|
28
|
+
return _ref.apply(this, arguments);
|
|
29
|
+
};
|
|
30
|
+
}());
|
|
8
31
|
//# sourceMappingURL=null-worker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/workers/null-worker.ts"],"names":["data"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/workers/null-worker.ts"],"names":["data"],"mappings":";;;;;;;;AAAA;;AAEA;AAAA,uEAAa,iBAAOA,IAAP;AAAA;AAAA;AAAA;AAAA;AAAA,6CAEJA,IAFI;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,GAAb;;AAAA;AAAA;AAAA;AAAA","sourcesContent":["import {createWorker} from '../lib/worker-api/create-worker';\n\ncreateWorker(async (data) => {\n // @ts-ignore\n return data;\n});\n"],"file":"null-worker.js"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const DEFAULT_VERSION = 'beta';
|
|
2
|
-
export const VERSION = typeof "3.0.
|
|
2
|
+
export const VERSION = typeof "3.0.14" !== 'undefined' ? "3.0.14" : DEFAULT_VERSION;
|
|
3
3
|
|
|
4
|
-
if (typeof "3.0.
|
|
4
|
+
if (typeof "3.0.14" === 'undefined') {
|
|
5
5
|
console.error('loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.');
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=version.js.map
|
|
@@ -3,7 +3,7 @@ import * as node from '../node/require-utils.node';
|
|
|
3
3
|
import { assert } from '../env-utils/assert';
|
|
4
4
|
import { VERSION as __VERSION__ } from '../env-utils/version';
|
|
5
5
|
const LATEST = 'beta';
|
|
6
|
-
const VERSION = typeof "3.0.
|
|
6
|
+
const VERSION = typeof "3.0.14" !== 'undefined' ? "3.0.14" : LATEST;
|
|
7
7
|
const loadLibraryPromises = {};
|
|
8
8
|
export async function loadLibrary(libraryUrl, moduleName = null, options = {}) {
|
|
9
9
|
if (moduleName) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assert } from '../env-utils/assert';
|
|
2
2
|
import { VERSION as __VERSION__ } from '../env-utils/version';
|
|
3
3
|
const NPM_TAG = 'latest';
|
|
4
|
-
const VERSION = typeof "3.0.
|
|
4
|
+
const VERSION = typeof "3.0.14" !== 'undefined' ? "3.0.14" : NPM_TAG;
|
|
5
5
|
export function getWorkerName(worker) {
|
|
6
6
|
const warning = worker.version !== VERSION ? " (worker-utils@".concat(VERSION, ")") : '';
|
|
7
7
|
return "".concat(worker.name, "@").concat(worker.version).concat(warning);
|
package/dist/null-worker.js
CHANGED
|
@@ -87,9 +87,9 @@
|
|
|
87
87
|
/******/ ({
|
|
88
88
|
|
|
89
89
|
/***/ "../../node_modules/@babel/runtime/helpers/defineProperty.js":
|
|
90
|
-
|
|
91
|
-
!*** /
|
|
92
|
-
|
|
90
|
+
/*!****************************************************************************************!*\
|
|
91
|
+
!*** /home/user/apps/loaders.gl/node_modules/@babel/runtime/helpers/defineProperty.js ***!
|
|
92
|
+
\****************************************************************************************/
|
|
93
93
|
/*! no static exports found */
|
|
94
94
|
/***/ (function(module, exports) {
|
|
95
95
|
|
package/dist/null-worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:////Users/kbarron/github/mapping/loaders.gl/node_modules/@babel/runtime/helpers/defineProperty.js","webpack:///./src/lib/async-queue/async-queue.ts","webpack:///./src/lib/worker-api/create-worker.ts","webpack:///./src/lib/worker-farm/worker-body.ts","webpack:///./src/lib/worker-utils/get-transfer-list.ts","webpack:///./src/workers/null-worker.ts"],"names":["Symbol","asyncIterator","AsyncQueue","constructor","_values","_settlers","_closed","push","value","enqueue","Error","length","settler","shift","reject","resolve","close","done","next","Promise","undefined","requestId","inputBatches","options","createWorker","process","processInBatches","self","context","processOnMainThread","WorkerBody","onmessage","type","payload","result","input","postMessage","resultIterator","batch","error","message","arrayBuffer","id","onMessage","removeEventListener","addEventListener","onMessageWrapperMap","Map","isKnownMessage","data","onMessageWrapper","get","delete","source","transferList","getTransferList","startsWith","object","recursive","transfers","transfersSet","Set","isTransferable","add","buffer","ArrayBuffer","isView","key","Array","from","MessagePort","ImageBitmap","OffscreenCanvas"],"mappings":";QAAA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;;QAGA;QACA;;;;;;;;;;;;AClFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL,GAAG;AACH;AACA;;AAEA;AACA;;AAEA;AACA,6E;;;;;;;;;;;;;;;;;;;;wBCWGA,MAAM,CAACC,a;AA3BV;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,MAAMC,UAAN,CAAoB;AAKjCC,aAAW,GAAG;AAAA;;AAAA;;AAAA;;AACZ,SAAKC,OAAL,GAAe,EAAf,CADY,CACO;;AACnB,SAAKC,SAAL,GAAiB,EAAjB,CAFY,CAES;;AACrB,SAAKC,OAAL,GAAe,KAAf;AACD;AAED;;;AACA,4BAA2C;AACzC,WAAO,IAAP;AACD;AAED;;;A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5DD;AAAA;AAAA;AAEAhD,kFAAY,CAAC,MAAOyB,IAAP,IAAgB;AAC3B;AACA,SAAOA,IAAP;AACD,CAHW,CAAZ,C","file":"null-worker.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./src/workers/null-worker.ts\");\n","function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}\n\nmodule.exports = _defineProperty;\nmodule.exports[\"default\"] = module.exports, module.exports.__esModule = true;","// From https://github.com/rauschma/async-iter-demo/tree/master/src under MIT license\n// http://2ality.com/2016/10/asynchronous-iteration.html\n\n/**\n * Async Queue\n * - AsyncIterable: An async iterator can be\n * - Values can be pushed onto the queue\n * @example\n * const asyncQueue = new AsyncQueue();\n * setTimeout(() => asyncQueue.enqueue('tick'), 1000);\n * setTimeout(() => asyncQueue.enqueue(new Error('done')), 10000);\n * for await (const value of asyncQueue) {\n * console.log(value); // tick\n * }\n */\nexport default class AsyncQueue<T> {\n private _values: any[];\n private _settlers: any[];\n private _closed: boolean;\n\n constructor() {\n this._values = []; // enqueues > dequeues\n this._settlers = []; // dequeues > enqueues\n this._closed = false;\n }\n\n /** Return an async iterator for this queue */\n [Symbol.asyncIterator](): AsyncIterator<T> {\n return this;\n }\n\n /** Push a new value - the async iterator will yield a promise resolved to this value */\n push(value: T): void {\n return this.enqueue(value);\n }\n\n /**\n * Push a new value - the async iterator will yield a promise resolved to this value\n * Add an error - the async iterator will yield a promise rejected with this value\n */\n enqueue(value: T | Error): void {\n if (this._closed) {\n throw new Error('Closed');\n }\n\n if (this._settlers.length > 0) {\n if (this._values.length > 0) {\n throw new Error('Illegal internal state');\n }\n const settler = this._settlers.shift();\n if (value instanceof Error) {\n settler.reject(value);\n } else {\n settler.resolve({value});\n }\n } else {\n this._values.push(value);\n }\n }\n\n /** Indicate that we not waiting for more values - The async iterator will be done */\n close(): void {\n while (this._settlers.length > 0) {\n const settler = this._settlers.shift();\n settler.resolve({done: true});\n }\n this._closed = true;\n }\n\n // ITERATOR IMPLEMENTATION\n\n /** @returns a Promise for an IteratorResult */\n next(): Promise<IteratorResult<T, any>> {\n // If values in queue, yield the first value\n if (this._values.length > 0) {\n const value = this._values.shift();\n if (value instanceof Error) {\n return Promise.reject(value);\n }\n return Promise.resolve({done: false, value});\n }\n\n // If queue is closed, the iterator is done\n if (this._closed) {\n if (this._settlers.length > 0) {\n throw new Error('Illegal internal state');\n }\n return Promise.resolve({done: true, value: undefined});\n }\n\n // Yield a promise that waits for new values to be enqueued\n return new Promise((resolve, reject) => {\n this._settlers.push({resolve, reject});\n });\n }\n}\n","import type {\n WorkerMessageType,\n WorkerMessagePayload,\n WorkerContext,\n Process,\n ProcessInBatches\n} from '../../types';\nimport AsyncQueue from '../async-queue/async-queue';\nimport WorkerBody from '../worker-farm/worker-body';\n// import {validateWorkerVersion} from './validate-worker-version';\n\n/** Counter for jobs */\nlet requestId = 0;\nlet inputBatches;\nlet options;\n\nexport type ProcessOnMainThread = (data: any, options?: {[key: string]: any}, context?) => any;\n\n/**\n * Set up a WebWorkerGlobalScope to talk with the main thread\n */\nexport function createWorker(process: Process, processInBatches?: ProcessInBatches): void {\n // Check that we are actually in a worker thread\n if (typeof self === 'undefined') {\n return;\n }\n\n const context: WorkerContext = {\n process: processOnMainThread\n };\n\n // eslint-disable-next-line complexity\n WorkerBody.onmessage = async (type: WorkerMessageType, payload: WorkerMessagePayload) => {\n try {\n switch (type) {\n case 'process':\n if (!process) {\n throw new Error('Worker does not support atomic processing');\n }\n const result = await process(payload.input, payload.options || {}, context);\n WorkerBody.postMessage('done', {result});\n break;\n\n case 'process-in-batches':\n if (!processInBatches) {\n throw new Error('Worker does not support batched processing');\n }\n inputBatches = new AsyncQueue();\n options = payload.options || {};\n const resultIterator = processInBatches(inputBatches, options, context?.processInBatches);\n for await (const batch of resultIterator) {\n WorkerBody.postMessage('output-batch', {result: batch});\n }\n WorkerBody.postMessage('done', {});\n break;\n\n case 'input-batch':\n inputBatches.push(payload.input);\n break;\n\n case 'input-done':\n inputBatches.close();\n break;\n\n default:\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : '';\n WorkerBody.postMessage('error', {error: message});\n }\n };\n}\n\nfunction processOnMainThread(arrayBuffer, options = {}) {\n return new Promise((resolve, reject) => {\n const id = requestId++;\n\n /**\n */\n const onMessage = (type, payload) => {\n if (payload.id !== id) {\n // not ours\n return;\n }\n\n switch (type) {\n case 'done':\n WorkerBody.removeEventListener(onMessage);\n resolve(payload.result);\n break;\n\n case 'error':\n WorkerBody.removeEventListener(onMessage);\n reject(payload.error);\n break;\n\n default:\n // ignore\n }\n };\n\n WorkerBody.addEventListener(onMessage);\n\n // Ask the main thread to decode data\n const payload = {id, input: arrayBuffer, options};\n WorkerBody.postMessage('process', payload);\n });\n}\n","import type {WorkerMessageData, WorkerMessageType, WorkerMessagePayload} from '../../types';\nimport {getTransferList} from '../worker-utils/get-transfer-list';\n\nconst onMessageWrapperMap = new Map();\n\n/**\n * Type safe wrapper for worker code\n */\nexport default class WorkerBody {\n /*\n * (type: WorkerMessageType, payload: WorkerMessagePayload) => any\n */\n static set onmessage(onMessage: (type: WorkerMessageType, payload: WorkerMessagePayload) => any) {\n // eslint-disable-next-line no-restricted-globals\n self.onmessage = (message) => {\n if (!isKnownMessage(message)) {\n return;\n }\n\n // Confusingly the message itself also has a 'type' field which is always set to 'message'\n const {type, payload} = message.data;\n onMessage(type, payload);\n };\n }\n\n static addEventListener(\n onMessage: (type: WorkerMessageType, payload: WorkerMessagePayload) => any\n ) {\n let onMessageWrapper = onMessageWrapperMap.get(onMessage);\n\n if (!onMessageWrapper) {\n onMessageWrapper = (message) => {\n if (!isKnownMessage(message)) {\n return;\n }\n\n // Confusingly the message itself also has a 'type' field which is always set to 'message'\n const {type, payload} = message.data;\n onMessage(type, payload);\n };\n }\n\n // eslint-disable-next-line no-restricted-globals\n self.addEventListener('message', onMessageWrapper);\n }\n\n static removeEventListener(\n onMessage: (type: WorkerMessageType, payload: WorkerMessagePayload) => any\n ) {\n const onMessageWrapper = onMessageWrapperMap.get(onMessage);\n onMessageWrapperMap.delete(onMessage);\n // eslint-disable-next-line no-restricted-globals\n self.removeEventListener('message', onMessageWrapper);\n }\n\n /**\n * Send a message from a worker to creating thread (main thread)\n * @param type\n * @param payload\n */\n static postMessage(type: WorkerMessageType, payload: WorkerMessagePayload): void {\n if (self) {\n const data: WorkerMessageData = {source: 'loaders.gl', type, payload};\n const transferList = getTransferList(payload);\n // eslint-disable-next-line no-restricted-globals\n // @ts-ignore\n self.postMessage(data, transferList);\n }\n }\n}\n\n// Filter out noise messages sent to workers\nfunction isKnownMessage(message) {\n const {type, data} = message;\n return (\n type === 'message' &&\n data &&\n typeof data.source === 'string' &&\n data.source.startsWith('loaders.gl')\n );\n}\n","// NOTE - there is a copy of this function is both in core and loader-utils\n// core does not need all the utils in loader-utils, just this one.\n\n/**\n * Returns an array of Transferrable objects that can be used with postMessage\n * https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage\n * @param object data to be sent via postMessage\n * @param recursive - not for application use\n * @param transfers - not for application use\n * @returns a transfer list that can be passed to postMessage\n */\nexport function getTransferList(\n object: any,\n recursive: boolean = true,\n transfers?: Set<any>\n): Transferable[] {\n // Make sure that items in the transfer list is unique\n const transfersSet = transfers || new Set();\n\n if (!object) {\n // ignore\n } else if (isTransferable(object)) {\n transfersSet.add(object);\n } else if (isTransferable(object.buffer)) {\n // Typed array\n transfersSet.add(object.buffer);\n } else if (ArrayBuffer.isView(object)) {\n // object is a TypeArray viewing into a SharedArrayBuffer (not transferable)\n // Do not iterate through the content in this case\n } else if (recursive && typeof object === 'object') {\n for (const key in object) {\n // Avoid perf hit - only go one level deep\n getTransferList(object[key], recursive, transfersSet);\n }\n }\n\n // If transfers is defined, is internal recursive call\n // Otherwise it's called by the user\n return transfers === undefined ? Array.from(transfersSet) : [];\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/API/Transferable\nfunction isTransferable(object) {\n if (!object) {\n return false;\n }\n if (object instanceof ArrayBuffer) {\n return true;\n }\n if (typeof MessagePort !== 'undefined' && object instanceof MessagePort) {\n return true;\n }\n if (typeof ImageBitmap !== 'undefined' && object instanceof ImageBitmap) {\n return true;\n }\n // @ts-ignore\n if (typeof OffscreenCanvas !== 'undefined' && object instanceof OffscreenCanvas) {\n return true;\n }\n return false;\n}\n","import {createWorker} from '../lib/worker-api/create-worker';\n\ncreateWorker(async (data) => {\n // @ts-ignore\n return data;\n});\n"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:////home/user/apps/loaders.gl/node_modules/@babel/runtime/helpers/defineProperty.js","webpack:///./src/lib/async-queue/async-queue.ts","webpack:///./src/lib/worker-api/create-worker.ts","webpack:///./src/lib/worker-farm/worker-body.ts","webpack:///./src/lib/worker-utils/get-transfer-list.ts","webpack:///./src/workers/null-worker.ts"],"names":["Symbol","asyncIterator","AsyncQueue","constructor","_values","_settlers","_closed","push","value","enqueue","Error","length","settler","shift","reject","resolve","close","done","next","Promise","undefined","requestId","inputBatches","options","createWorker","process","processInBatches","self","context","processOnMainThread","WorkerBody","onmessage","type","payload","result","input","postMessage","resultIterator","batch","error","message","arrayBuffer","id","onMessage","removeEventListener","addEventListener","onMessageWrapperMap","Map","isKnownMessage","data","onMessageWrapper","get","delete","source","transferList","getTransferList","startsWith","object","recursive","transfers","transfersSet","Set","isTransferable","add","buffer","ArrayBuffer","isView","key","Array","from","MessagePort","ImageBitmap","OffscreenCanvas"],"mappings":";QAAA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA,yCAAyC,iCAAiC;QAC1E,gHAAgH,mBAAmB,EAAE;QACrI;QACA;;QAEA;QACA;QACA;QACA,2BAA2B,0BAA0B,EAAE;QACvD,iCAAiC,eAAe;QAChD;QACA;QACA;;QAEA;QACA,sDAAsD,+DAA+D;;QAErH;QACA;;;QAGA;QACA;;;;;;;;;;;;AClFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL,GAAG;AACH;AACA;;AAEA;AACA;;AAEA;AACA,6E;;;;;;;;;;;;;;;;;;;;wBCWGA,MAAM,CAACC,a;AA3BV;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,MAAMC,UAAN,CAAoB;AAKjCC,aAAW,GAAG;AAAA;;AAAA;;AAAA;;AACZ,SAAKC,OAAL,GAAe,EAAf,CADY,CACO;;AACnB,SAAKC,SAAL,GAAiB,EAAjB,CAFY,CAES;;AACrB,SAAKC,OAAL,GAAe,KAAf;AACD;AAED;;;AACA,4BAA2C;AACzC,WAAO,IAAP;AACD;AAED;;;AACAC,MAAI,CAACC,KAAD,EAAiB;AACnB,WAAO,KAAKC,OAAL,CAAaD,KAAb,CAAP;AACD;AAED;AACF;AACA;AACA;;;AACEC,SAAO,CAACD,KAAD,EAAyB;AAC9B,QAAI,KAAKF,OAAT,EA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The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./src/workers/null-worker.ts\");\n","function _defineProperty(obj, key, value) {\n if (key in obj) {\n Object.defineProperty(obj, key, {\n value: value,\n enumerable: true,\n configurable: true,\n writable: true\n });\n } else {\n obj[key] = value;\n }\n\n return obj;\n}\n\nmodule.exports = _defineProperty;\nmodule.exports[\"default\"] = module.exports, module.exports.__esModule = true;","// From https://github.com/rauschma/async-iter-demo/tree/master/src under MIT license\n// http://2ality.com/2016/10/asynchronous-iteration.html\n\n/**\n * Async Queue\n * - AsyncIterable: An async iterator can be\n * - Values can be pushed onto the queue\n * @example\n * const asyncQueue = new AsyncQueue();\n * setTimeout(() => asyncQueue.enqueue('tick'), 1000);\n * setTimeout(() => asyncQueue.enqueue(new Error('done')), 10000);\n * for await (const value of asyncQueue) {\n * console.log(value); // tick\n * }\n */\nexport default class AsyncQueue<T> {\n private _values: any[];\n private _settlers: any[];\n private _closed: boolean;\n\n constructor() {\n this._values = []; // enqueues > dequeues\n this._settlers = []; // dequeues > enqueues\n this._closed = false;\n }\n\n /** Return an async iterator for this queue */\n [Symbol.asyncIterator](): AsyncIterator<T> {\n return this;\n }\n\n /** Push a new value - the async iterator will yield a promise resolved to this value */\n push(value: T): void {\n return this.enqueue(value);\n }\n\n /**\n * Push a new value - the async iterator will yield a promise resolved to this value\n * Add an error - the async iterator will yield a promise rejected with this value\n */\n enqueue(value: T | Error): void {\n if (this._closed) {\n throw new Error('Closed');\n }\n\n if (this._settlers.length > 0) {\n if (this._values.length > 0) {\n throw new Error('Illegal internal state');\n }\n const settler = this._settlers.shift();\n if (value instanceof Error) {\n settler.reject(value);\n } else {\n settler.resolve({value});\n }\n } else {\n this._values.push(value);\n }\n }\n\n /** Indicate that we not waiting for more values - The async iterator will be done */\n close(): void {\n while (this._settlers.length > 0) {\n const settler = this._settlers.shift();\n settler.resolve({done: true});\n }\n this._closed = true;\n }\n\n // ITERATOR IMPLEMENTATION\n\n /** @returns a Promise for an IteratorResult */\n next(): Promise<IteratorResult<T, any>> {\n // If values in queue, yield the first value\n if (this._values.length > 0) {\n const value = this._values.shift();\n if (value instanceof Error) {\n return Promise.reject(value);\n }\n return Promise.resolve({done: false, value});\n }\n\n // If queue is closed, the iterator is done\n if (this._closed) {\n if (this._settlers.length > 0) {\n throw new Error('Illegal internal state');\n }\n return Promise.resolve({done: true, value: undefined});\n }\n\n // Yield a promise that waits for new values to be enqueued\n return new Promise((resolve, reject) => {\n this._settlers.push({resolve, reject});\n });\n }\n}\n","import type {\n WorkerMessageType,\n WorkerMessagePayload,\n WorkerContext,\n Process,\n ProcessInBatches\n} from '../../types';\nimport AsyncQueue from '../async-queue/async-queue';\nimport WorkerBody from '../worker-farm/worker-body';\n// import {validateWorkerVersion} from './validate-worker-version';\n\n/** Counter for jobs */\nlet requestId = 0;\nlet inputBatches;\nlet options;\n\nexport type ProcessOnMainThread = (data: any, options?: {[key: string]: any}, context?) => any;\n\n/**\n * Set up a WebWorkerGlobalScope to talk with the main thread\n */\nexport function createWorker(process: Process, processInBatches?: ProcessInBatches): void {\n // Check that we are actually in a worker thread\n if (typeof self === 'undefined') {\n return;\n }\n\n const context: WorkerContext = {\n process: processOnMainThread\n };\n\n // eslint-disable-next-line complexity\n WorkerBody.onmessage = async (type: WorkerMessageType, payload: WorkerMessagePayload) => {\n try {\n switch (type) {\n case 'process':\n if (!process) {\n throw new Error('Worker does not support atomic processing');\n }\n const result = await process(payload.input, payload.options || {}, context);\n WorkerBody.postMessage('done', {result});\n break;\n\n case 'process-in-batches':\n if (!processInBatches) {\n throw new Error('Worker does not support batched processing');\n }\n inputBatches = new AsyncQueue();\n options = payload.options || {};\n const resultIterator = processInBatches(inputBatches, options, context?.processInBatches);\n for await (const batch of resultIterator) {\n WorkerBody.postMessage('output-batch', {result: batch});\n }\n WorkerBody.postMessage('done', {});\n break;\n\n case 'input-batch':\n inputBatches.push(payload.input);\n break;\n\n case 'input-done':\n inputBatches.close();\n break;\n\n default:\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : '';\n WorkerBody.postMessage('error', {error: message});\n }\n };\n}\n\nfunction processOnMainThread(arrayBuffer, options = {}) {\n return new Promise((resolve, reject) => {\n const id = requestId++;\n\n /**\n */\n const onMessage = (type, payload) => {\n if (payload.id !== id) {\n // not ours\n return;\n }\n\n switch (type) {\n case 'done':\n WorkerBody.removeEventListener(onMessage);\n resolve(payload.result);\n break;\n\n case 'error':\n WorkerBody.removeEventListener(onMessage);\n reject(payload.error);\n break;\n\n default:\n // ignore\n }\n };\n\n WorkerBody.addEventListener(onMessage);\n\n // Ask the main thread to decode data\n const payload = {id, input: arrayBuffer, options};\n WorkerBody.postMessage('process', payload);\n });\n}\n","import type {WorkerMessageData, WorkerMessageType, WorkerMessagePayload} from '../../types';\nimport {getTransferList} from '../worker-utils/get-transfer-list';\n\nconst onMessageWrapperMap = new Map();\n\n/**\n * Type safe wrapper for worker code\n */\nexport default class WorkerBody {\n /*\n * (type: WorkerMessageType, payload: WorkerMessagePayload) => any\n */\n static set onmessage(onMessage: (type: WorkerMessageType, payload: WorkerMessagePayload) => any) {\n // eslint-disable-next-line no-restricted-globals\n self.onmessage = (message) => {\n if (!isKnownMessage(message)) {\n return;\n }\n\n // Confusingly the message itself also has a 'type' field which is always set to 'message'\n const {type, payload} = message.data;\n onMessage(type, payload);\n };\n }\n\n static addEventListener(\n onMessage: (type: WorkerMessageType, payload: WorkerMessagePayload) => any\n ) {\n let onMessageWrapper = onMessageWrapperMap.get(onMessage);\n\n if (!onMessageWrapper) {\n onMessageWrapper = (message) => {\n if (!isKnownMessage(message)) {\n return;\n }\n\n // Confusingly the message itself also has a 'type' field which is always set to 'message'\n const {type, payload} = message.data;\n onMessage(type, payload);\n };\n }\n\n // eslint-disable-next-line no-restricted-globals\n self.addEventListener('message', onMessageWrapper);\n }\n\n static removeEventListener(\n onMessage: (type: WorkerMessageType, payload: WorkerMessagePayload) => any\n ) {\n const onMessageWrapper = onMessageWrapperMap.get(onMessage);\n onMessageWrapperMap.delete(onMessage);\n // eslint-disable-next-line no-restricted-globals\n self.removeEventListener('message', onMessageWrapper);\n }\n\n /**\n * Send a message from a worker to creating thread (main thread)\n * @param type\n * @param payload\n */\n static postMessage(type: WorkerMessageType, payload: WorkerMessagePayload): void {\n if (self) {\n const data: WorkerMessageData = {source: 'loaders.gl', type, payload};\n const transferList = getTransferList(payload);\n // eslint-disable-next-line no-restricted-globals\n // @ts-ignore\n self.postMessage(data, transferList);\n }\n }\n}\n\n// Filter out noise messages sent to workers\nfunction isKnownMessage(message) {\n const {type, data} = message;\n return (\n type === 'message' &&\n data &&\n typeof data.source === 'string' &&\n data.source.startsWith('loaders.gl')\n );\n}\n","// NOTE - there is a copy of this function is both in core and loader-utils\n// core does not need all the utils in loader-utils, just this one.\n\n/**\n * Returns an array of Transferrable objects that can be used with postMessage\n * https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage\n * @param object data to be sent via postMessage\n * @param recursive - not for application use\n * @param transfers - not for application use\n * @returns a transfer list that can be passed to postMessage\n */\nexport function getTransferList(\n object: any,\n recursive: boolean = true,\n transfers?: Set<any>\n): Transferable[] {\n // Make sure that items in the transfer list is unique\n const transfersSet = transfers || new Set();\n\n if (!object) {\n // ignore\n } else if (isTransferable(object)) {\n transfersSet.add(object);\n } else if (isTransferable(object.buffer)) {\n // Typed array\n transfersSet.add(object.buffer);\n } else if (ArrayBuffer.isView(object)) {\n // object is a TypeArray viewing into a SharedArrayBuffer (not transferable)\n // Do not iterate through the content in this case\n } else if (recursive && typeof object === 'object') {\n for (const key in object) {\n // Avoid perf hit - only go one level deep\n getTransferList(object[key], recursive, transfersSet);\n }\n }\n\n // If transfers is defined, is internal recursive call\n // Otherwise it's called by the user\n return transfers === undefined ? Array.from(transfersSet) : [];\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/API/Transferable\nfunction isTransferable(object) {\n if (!object) {\n return false;\n }\n if (object instanceof ArrayBuffer) {\n return true;\n }\n if (typeof MessagePort !== 'undefined' && object instanceof MessagePort) {\n return true;\n }\n if (typeof ImageBitmap !== 'undefined' && object instanceof ImageBitmap) {\n return true;\n }\n // @ts-ignore\n if (typeof OffscreenCanvas !== 'undefined' && object instanceof OffscreenCanvas) {\n return true;\n }\n return false;\n}\n","import {createWorker} from '../lib/worker-api/create-worker';\n\ncreateWorker(async (data) => {\n // @ts-ignore\n return data;\n});\n"],"sourceRoot":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/worker-utils",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.14",
|
|
4
4
|
"description": "Utilities for running tasks on worker threads",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@babel/runtime": "^7.3.1"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "dc931768fc34de549ef6baeb94e2ee5aa8163baf"
|
|
47
47
|
}
|