@loaders.gl/worker-utils 3.3.0-alpha.4 → 3.3.0-alpha.5
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/lib/env-utils/version.js +2 -2
- package/dist/es5/lib/library-utils/library-utils.js +1 -1
- package/dist/es5/lib/worker-api/get-worker-url.js +1 -1
- package/dist/es5/lib/worker-utils/get-transfer-list.js +1 -1
- package/dist/es5/lib/worker-utils/get-transfer-list.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/esm/lib/worker-utils/get-transfer-list.js +1 -1
- package/dist/esm/lib/worker-utils/get-transfer-list.js.map +1 -1
- package/dist/lib/worker-utils/get-transfer-list.d.ts.map +1 -1
- package/dist/lib/worker-utils/get-transfer-list.js +4 -2
- package/dist/null-worker.js.map +1 -1
- package/package.json +2 -2
- package/src/lib/worker-utils/get-transfer-list.ts +6 -2
|
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.VERSION = void 0;
|
|
7
7
|
var DEFAULT_VERSION = 'beta';
|
|
8
|
-
var VERSION = typeof "3.3.0-alpha.
|
|
8
|
+
var VERSION = typeof "3.3.0-alpha.5" !== 'undefined' ? "3.3.0-alpha.5" : DEFAULT_VERSION;
|
|
9
9
|
exports.VERSION = VERSION;
|
|
10
10
|
|
|
11
|
-
if (typeof "3.3.0-alpha.
|
|
11
|
+
if (typeof "3.3.0-alpha.5" === 'undefined') {
|
|
12
12
|
console.error('loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.');
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=version.js.map
|
|
@@ -27,7 +27,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
27
27
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
28
28
|
|
|
29
29
|
var LATEST = 'beta';
|
|
30
|
-
var VERSION = typeof "3.3.0-alpha.
|
|
30
|
+
var VERSION = typeof "3.3.0-alpha.5" !== 'undefined' ? "3.3.0-alpha.5" : LATEST;
|
|
31
31
|
var loadLibraryPromises = {};
|
|
32
32
|
|
|
33
33
|
function loadLibrary(_x) {
|
|
@@ -11,7 +11,7 @@ var _assert = require("../env-utils/assert");
|
|
|
11
11
|
var _version = require("../env-utils/version");
|
|
12
12
|
|
|
13
13
|
var NPM_TAG = 'beta';
|
|
14
|
-
var VERSION = typeof "3.3.0-alpha.
|
|
14
|
+
var VERSION = typeof "3.3.0-alpha.5" !== 'undefined' ? "3.3.0-alpha.5" : NPM_TAG;
|
|
15
15
|
|
|
16
16
|
function getWorkerName(worker) {
|
|
17
17
|
var warning = worker.version !== VERSION ? " (worker-utils@".concat(VERSION, ")") : '';
|
|
@@ -59,7 +59,7 @@ function getTransferListForWriter(object) {
|
|
|
59
59
|
|
|
60
60
|
var clone = Object.assign({}, object);
|
|
61
61
|
Object.keys(clone).forEach(function (key) {
|
|
62
|
-
if ((0, _typeof2.default)(object[key]) === 'object' && !ArrayBuffer.isView(object[key])) {
|
|
62
|
+
if ((0, _typeof2.default)(object[key]) === 'object' && !ArrayBuffer.isView(object[key]) && !(object[key] instanceof Array)) {
|
|
63
63
|
clone[key] = getTransferListForWriter(object[key]);
|
|
64
64
|
} else if (typeof clone[key] === 'function' || clone[key] instanceof RegExp) {
|
|
65
65
|
clone[key] = {};
|
|
@@ -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","getTransferListForWriter","clone","Object","assign","keys","forEach","RegExp"],"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,EAAyC;AACvC,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;;AAMM,SAASC,wBAAT,CAAkCjB,MAAlC,EAAiE;AACtE,MAAIA,MAAM,KAAK,IAAf,EAAqB;AACnB,WAAO,EAAP;AACD;;AACD,MAAMkB,KAAK,GAAGC,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkBpB,MAAlB,CAAd;AAEAmB,EAAAA,MAAM,CAACE,IAAP,CAAYH,KAAZ,EAAmBI,OAAnB,CAA2B,UAACZ,GAAD,EAAS;AAElC,
|
|
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","getTransferListForWriter","clone","Object","assign","keys","forEach","RegExp"],"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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AZ,EAAmBI,OAAnB,CAA2B,UAACZ,GAAD,EAAS;AAElC,QACE,sBAAOV,MAAM,CAACU,GAAD,CAAb,MAAuB,QAAvB,IACA,CAACF,WAAW,CAACC,MAAZ,CAAmBT,MAAM,CAACU,GAAD,CAAzB,CADD,IAEA,EAAEV,MAAM,CAACU,GAAD,CAAN,YAAuBE,KAAzB,CAHF,EAIE;AACAM,MAAAA,KAAK,CAACR,GAAD,CAAL,GAAaO,wBAAwB,CAACjB,MAAM,CAACU,GAAD,CAAP,CAArC;AACD,KAND,MAMO,IAAI,OAAOQ,KAAK,CAACR,GAAD,CAAZ,KAAsB,UAAtB,IAAoCQ,KAAK,CAACR,GAAD,CAAL,YAAsBa,MAA9D,EAAsE;AAC3EL,MAAAA,KAAK,CAACR,GAAD,CAAL,GAAa,EAAb;AACD,KAFM,MAEA;AACLQ,MAAAA,KAAK,CAACR,GAAD,CAAL,GAAaV,MAAM,CAACU,GAAD,CAAnB;AACD;AACF,GAbD;AAeA,SAAOQ,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: unknown) {\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\n/**\n * Recursively drop non serializable values like functions and regexps.\n * @param object\n */\nexport function getTransferListForWriter(object: object | null): object {\n if (object === null) {\n return {};\n }\n const clone = Object.assign({}, object);\n\n Object.keys(clone).forEach((key) => {\n // Typed Arrays and Arrays are passed with no change\n if (\n typeof object[key] === 'object' &&\n !ArrayBuffer.isView(object[key]) &&\n !(object[key] instanceof Array)\n ) {\n clone[key] = getTransferListForWriter(object[key]);\n } else if (typeof clone[key] === 'function' || clone[key] instanceof RegExp) {\n clone[key] = {};\n } else {\n clone[key] = object[key];\n }\n });\n\n return clone;\n}\n"],"file":"get-transfer-list.js"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const DEFAULT_VERSION = 'beta';
|
|
2
|
-
export const VERSION = typeof "3.3.0-alpha.
|
|
2
|
+
export const VERSION = typeof "3.3.0-alpha.5" !== 'undefined' ? "3.3.0-alpha.5" : DEFAULT_VERSION;
|
|
3
3
|
|
|
4
|
-
if (typeof "3.3.0-alpha.
|
|
4
|
+
if (typeof "3.3.0-alpha.5" === '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.3.0-alpha.
|
|
6
|
+
const VERSION = typeof "3.3.0-alpha.5" !== 'undefined' ? "3.3.0-alpha.5" : 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 = 'beta';
|
|
4
|
-
const VERSION = typeof "3.3.0-alpha.
|
|
4
|
+
const VERSION = typeof "3.3.0-alpha.5" !== 'undefined' ? "3.3.0-alpha.5" : 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);
|
|
@@ -45,7 +45,7 @@ export function getTransferListForWriter(object) {
|
|
|
45
45
|
|
|
46
46
|
const clone = Object.assign({}, object);
|
|
47
47
|
Object.keys(clone).forEach(key => {
|
|
48
|
-
if (typeof object[key] === 'object' && !ArrayBuffer.isView(object[key])) {
|
|
48
|
+
if (typeof object[key] === 'object' && !ArrayBuffer.isView(object[key]) && !(object[key] instanceof Array)) {
|
|
49
49
|
clone[key] = getTransferListForWriter(object[key]);
|
|
50
50
|
} else if (typeof clone[key] === 'function' || clone[key] instanceof RegExp) {
|
|
51
51
|
clone[key] = {};
|
|
@@ -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","getTransferListForWri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IAA0ChB,MAAM,YAAYgB,eAAhE,EAAiF;AAC/E,WAAO,IAAP;AACD;;AACD,SAAO,KAAP;AACD;;AAMD,OAAO,SAASC,wBAAT,CAAkCjB,MAAlC,EAAiE;AACtE,MAAIA,MAAM,KAAK,IAAf,EAAqB;AACnB,WAAO,EAAP;AACD;;AACD,QAAMkB,KAAK,GAAGC,MAAM,CAACC,MAAP,CAAc,EAAd,EAAkBpB,MAAlB,CAAd;AAEAmB,EAAAA,MAAM,CAACE,IAAP,CAAYH,KAAZ,EAAmBI,OAAnB,CAA4BZ,GAAD,IAAS;AAElC,
|
|
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","getTransferListForWriter","clone","Object","assign","keys","forEach","RegExp"],"mappings":"AAWA,OAAO,SAASA,eAAT,CACLC,MADK,EAELC,SAAkB,GAAG,IAFhB,EAGLC,SAHK,EAIW;AAEhB,QAAMC,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,OAAOD,MAAP,KAAkB,QAAnC,EAA6C;AAClD,SAAK,MAAMU,GAAX,IAAkBV,MAAlB,EAA0B;AAExBD,MAAAA,eAAe,CAACC,MAAM,CAACU,GAAD,C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AD,CAAZ,KAAsB,UAAtB,IAAoCQ,KAAK,CAACR,GAAD,CAAL,YAAsBa,MAA9D,EAAsE;AAC3EL,MAAAA,KAAK,CAACR,GAAD,CAAL,GAAa,EAAb;AACD,KAFM,MAEA;AACLQ,MAAAA,KAAK,CAACR,GAAD,CAAL,GAAaV,MAAM,CAACU,GAAD,CAAnB;AACD;AACF,GAbD;AAeA,SAAOQ,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: unknown) {\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\n/**\n * Recursively drop non serializable values like functions and regexps.\n * @param object\n */\nexport function getTransferListForWriter(object: object | null): object {\n if (object === null) {\n return {};\n }\n const clone = Object.assign({}, object);\n\n Object.keys(clone).forEach((key) => {\n // Typed Arrays and Arrays are passed with no change\n if (\n typeof object[key] === 'object' &&\n !ArrayBuffer.isView(object[key]) &&\n !(object[key] instanceof Array)\n ) {\n clone[key] = getTransferListForWriter(object[key]);\n } else if (typeof clone[key] === 'function' || clone[key] instanceof RegExp) {\n clone[key] = {};\n } else {\n clone[key] = object[key];\n }\n });\n\n return clone;\n}\n"],"file":"get-transfer-list.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-transfer-list.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-utils/get-transfer-list.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,GAAG,EACX,SAAS,GAAE,OAAc,EACzB,SAAS,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GACnB,YAAY,EAAE,CAwBhB;AAuBD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"get-transfer-list.d.ts","sourceRoot":"","sources":["../../../src/lib/worker-utils/get-transfer-list.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,GAAG,EACX,SAAS,GAAE,OAAc,EACzB,SAAS,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GACnB,YAAY,EAAE,CAwBhB;AAuBD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAsBtE"}
|
|
@@ -69,8 +69,10 @@ function getTransferListForWriter(object) {
|
|
|
69
69
|
}
|
|
70
70
|
const clone = Object.assign({}, object);
|
|
71
71
|
Object.keys(clone).forEach((key) => {
|
|
72
|
-
//
|
|
73
|
-
if (typeof object[key] === 'object' &&
|
|
72
|
+
// Typed Arrays and Arrays are passed with no change
|
|
73
|
+
if (typeof object[key] === 'object' &&
|
|
74
|
+
!ArrayBuffer.isView(object[key]) &&
|
|
75
|
+
!(object[key] instanceof Array)) {
|
|
74
76
|
clone[key] = getTransferListForWriter(object[key]);
|
|
75
77
|
}
|
|
76
78
|
else if (typeof clone[key] === 'function' || clone[key] instanceof RegExp) {
|
package/dist/null-worker.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/lib/async-queue/async-queue.ts", "../src/lib/worker-utils/get-transfer-list.ts", "../src/lib/worker-farm/worker-body.ts", "../src/lib/worker-api/create-worker.ts", "../src/workers/null-worker.ts"],
|
|
4
|
-
"sourcesContent": ["// 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", "// 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: unknown) {\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\n/**\n * Recursively drop non serializable values like functions and regexps.\n * @param object\n */\nexport function getTransferListForWriter(object: object | null): object {\n if (object === null) {\n return {};\n }\n const clone = Object.assign({}, object);\n\n Object.keys(clone).forEach((key) => {\n // Checking if it is an object and not a typed array.\n if (typeof object[key] === 'object' && !ArrayBuffer.isView(object[key])) {\n clone[key] = getTransferListForWriter(object[key]);\n } else if (typeof clone[key] === 'function' || clone[key] instanceof RegExp) {\n clone[key] = {};\n } else {\n clone[key] = object[key];\n }\n });\n\n return clone;\n}\n", "import type {WorkerMessageData, WorkerMessageType, WorkerMessagePayload} from '../../types';\nimport {getTransferList} from '../worker-utils/get-transfer-list';\n\n/** Vile hack to defeat over-zealous bundlers from stripping out the require */\nfunction getParentPort() {\n // const isNode = globalThis.process;\n let parentPort;\n try {\n // prettier-ignore\n eval('globalThis.parentPort = require(\\'worker_threads\\').parentPort'); // eslint-disable-line no-eval\n parentPort = globalThis.parentPort;\n // eslint-disable-next-line no-empty\n } catch {}\n return parentPort;\n}\n\nconst onMessageWrapperMap = new Map();\n\n/**\n * Type safe wrapper for worker code\n */\nexport default class WorkerBody {\n /** Check that we are actually in a worker thread */\n static inWorkerThread(): boolean {\n return typeof self !== 'undefined' || Boolean(getParentPort());\n }\n\n /*\n * (type: WorkerMessageType, payload: WorkerMessagePayload) => any\n */\n static set onmessage(onMessage: (type: WorkerMessageType, payload: WorkerMessagePayload) => any) {\n function handleMessage(message) {\n // Confusingly the message itself also has a 'type' field which is always set to 'message'\n const parentPort = getParentPort();\n const {type, payload} = parentPort ? message : message.data;\n // if (!isKnownMessage(message)) {\n // return;\n // }\n onMessage(type, payload);\n }\n\n const parentPort = getParentPort();\n if (parentPort) {\n parentPort.on('message', handleMessage);\n // if (message == 'exit') { parentPort.unref(); }\n // eslint-disable-next-line\n parentPort.on('exit', () => console.debug('Node worker closing'));\n } else {\n // eslint-disable-next-line no-restricted-globals\n globalThis.onmessage = handleMessage;\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: MessageEvent<any>) => {\n if (!isKnownMessage(message)) {\n return;\n }\n\n // Confusingly in the browser, the message itself also has a 'type' field which is always set to 'message'\n const parentPort = getParentPort();\n const {type, payload} = parentPort ? message : message.data;\n onMessage(type, payload);\n };\n }\n\n const parentPort = getParentPort();\n if (parentPort) {\n console.error('not implemented'); // eslint-disable-line\n } else {\n globalThis.addEventListener('message', onMessageWrapper);\n }\n }\n\n static removeEventListener(\n onMessage: (type: WorkerMessageType, payload: WorkerMessagePayload) => any\n ) {\n const onMessageWrapper = onMessageWrapperMap.get(onMessage);\n onMessageWrapperMap.delete(onMessage);\n const parentPort = getParentPort();\n if (parentPort) {\n console.error('not implemented'); // eslint-disable-line\n } else {\n globalThis.removeEventListener('message', onMessageWrapper);\n }\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 const data: WorkerMessageData = {source: 'loaders.gl', type, payload};\n // console.log('posting message', data);\n const transferList = getTransferList(payload);\n\n const parentPort = getParentPort();\n if (parentPort) {\n parentPort.postMessage(data, transferList);\n // console.log('posted message', data);\n } else {\n // @ts-ignore\n globalThis.postMessage(data, transferList);\n }\n }\n}\n\n// Filter out noise messages sent to workers\nfunction isKnownMessage(message: MessageEvent<any>) {\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", "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: AsyncQueue<any>;\nlet options: {[key: string]: any};\n\nexport type ProcessOnMainThread = (\n data: any,\n options?: {[key: string]: any},\n context?: WorkerContext\n) => any;\n\n/**\n * Set up a WebWorkerGlobalScope to talk with the main thread\n */\nexport function createWorker(process: Process, processInBatches?: ProcessInBatches): void {\n if (!WorkerBody.inWorkerThread()) {\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<any>();\n options = payload.options || {};\n const resultIterator = processInBatches(inputBatches, options, context);\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: ArrayBuffer, options = {}) {\n return new Promise((resolve, reject) => {\n const id = requestId++;\n\n /**\n */\n const onMessage = (type: string, payload: WorkerMessagePayload) => {\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 {createWorker} from '../lib/worker-api/create-worker';\n\ncreateWorker(async (data) => {\n // @ts-ignore\n return data;\n});\n"],
|
|
4
|
+
"sourcesContent": ["// 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", "// 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: unknown) {\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\n/**\n * Recursively drop non serializable values like functions and regexps.\n * @param object\n */\nexport function getTransferListForWriter(object: object | null): object {\n if (object === null) {\n return {};\n }\n const clone = Object.assign({}, object);\n\n Object.keys(clone).forEach((key) => {\n // Typed Arrays and Arrays are passed with no change\n if (\n typeof object[key] === 'object' &&\n !ArrayBuffer.isView(object[key]) &&\n !(object[key] instanceof Array)\n ) {\n clone[key] = getTransferListForWriter(object[key]);\n } else if (typeof clone[key] === 'function' || clone[key] instanceof RegExp) {\n clone[key] = {};\n } else {\n clone[key] = object[key];\n }\n });\n\n return clone;\n}\n", "import type {WorkerMessageData, WorkerMessageType, WorkerMessagePayload} from '../../types';\nimport {getTransferList} from '../worker-utils/get-transfer-list';\n\n/** Vile hack to defeat over-zealous bundlers from stripping out the require */\nfunction getParentPort() {\n // const isNode = globalThis.process;\n let parentPort;\n try {\n // prettier-ignore\n eval('globalThis.parentPort = require(\\'worker_threads\\').parentPort'); // eslint-disable-line no-eval\n parentPort = globalThis.parentPort;\n // eslint-disable-next-line no-empty\n } catch {}\n return parentPort;\n}\n\nconst onMessageWrapperMap = new Map();\n\n/**\n * Type safe wrapper for worker code\n */\nexport default class WorkerBody {\n /** Check that we are actually in a worker thread */\n static inWorkerThread(): boolean {\n return typeof self !== 'undefined' || Boolean(getParentPort());\n }\n\n /*\n * (type: WorkerMessageType, payload: WorkerMessagePayload) => any\n */\n static set onmessage(onMessage: (type: WorkerMessageType, payload: WorkerMessagePayload) => any) {\n function handleMessage(message) {\n // Confusingly the message itself also has a 'type' field which is always set to 'message'\n const parentPort = getParentPort();\n const {type, payload} = parentPort ? message : message.data;\n // if (!isKnownMessage(message)) {\n // return;\n // }\n onMessage(type, payload);\n }\n\n const parentPort = getParentPort();\n if (parentPort) {\n parentPort.on('message', handleMessage);\n // if (message == 'exit') { parentPort.unref(); }\n // eslint-disable-next-line\n parentPort.on('exit', () => console.debug('Node worker closing'));\n } else {\n // eslint-disable-next-line no-restricted-globals\n globalThis.onmessage = handleMessage;\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: MessageEvent<any>) => {\n if (!isKnownMessage(message)) {\n return;\n }\n\n // Confusingly in the browser, the message itself also has a 'type' field which is always set to 'message'\n const parentPort = getParentPort();\n const {type, payload} = parentPort ? message : message.data;\n onMessage(type, payload);\n };\n }\n\n const parentPort = getParentPort();\n if (parentPort) {\n console.error('not implemented'); // eslint-disable-line\n } else {\n globalThis.addEventListener('message', onMessageWrapper);\n }\n }\n\n static removeEventListener(\n onMessage: (type: WorkerMessageType, payload: WorkerMessagePayload) => any\n ) {\n const onMessageWrapper = onMessageWrapperMap.get(onMessage);\n onMessageWrapperMap.delete(onMessage);\n const parentPort = getParentPort();\n if (parentPort) {\n console.error('not implemented'); // eslint-disable-line\n } else {\n globalThis.removeEventListener('message', onMessageWrapper);\n }\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 const data: WorkerMessageData = {source: 'loaders.gl', type, payload};\n // console.log('posting message', data);\n const transferList = getTransferList(payload);\n\n const parentPort = getParentPort();\n if (parentPort) {\n parentPort.postMessage(data, transferList);\n // console.log('posted message', data);\n } else {\n // @ts-ignore\n globalThis.postMessage(data, transferList);\n }\n }\n}\n\n// Filter out noise messages sent to workers\nfunction isKnownMessage(message: MessageEvent<any>) {\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", "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: AsyncQueue<any>;\nlet options: {[key: string]: any};\n\nexport type ProcessOnMainThread = (\n data: any,\n options?: {[key: string]: any},\n context?: WorkerContext\n) => any;\n\n/**\n * Set up a WebWorkerGlobalScope to talk with the main thread\n */\nexport function createWorker(process: Process, processInBatches?: ProcessInBatches): void {\n if (!WorkerBody.inWorkerThread()) {\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<any>();\n options = payload.options || {};\n const resultIterator = processInBatches(inputBatches, options, context);\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: ArrayBuffer, options = {}) {\n return new Promise((resolve, reject) => {\n const id = requestId++;\n\n /**\n */\n const onMessage = (type: string, payload: WorkerMessagePayload) => {\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 {createWorker} from '../lib/worker-api/create-worker';\n\ncreateWorker(async (data) => {\n // @ts-ignore\n return data;\n});\n"],
|
|
5
5
|
"mappings": ";;AAeA,yBAAmC;AAAA,IAKjC,cAAc;AACZ,WAAK,UAAU;AACf,WAAK,YAAY;AACjB,WAAK,UAAU;AAAA;AAAA,KAIhB,OAAO,iBAAmC;AACzC,aAAO;AAAA;AAAA,IAIT,KAAK,OAAgB;AACnB,aAAO,KAAK,QAAQ;AAAA;AAAA,IAOtB,QAAQ,OAAwB;AAC9B,UAAI,KAAK,SAAS;AAChB,cAAM,IAAI,MAAM;AAAA;AAGlB,UAAI,KAAK,UAAU,SAAS,GAAG;AAC7B,YAAI,KAAK,QAAQ,SAAS,GAAG;AAC3B,gBAAM,IAAI,MAAM;AAAA;AAElB,cAAM,UAAU,KAAK,UAAU;AAC/B,YAAI,iBAAiB,OAAO;AAC1B,kBAAQ,OAAO;AAAA,eACV;AACL,kBAAQ,QAAQ,EAAC;AAAA;AAAA,aAEd;AACL,aAAK,QAAQ,KAAK;AAAA;AAAA;AAAA,IAKtB,QAAc;AACZ,aAAO,KAAK,UAAU,SAAS,GAAG;AAChC,cAAM,UAAU,KAAK,UAAU;AAC/B,gBAAQ,QAAQ,EAAC,MAAM;AAAA;AAEzB,WAAK,UAAU;AAAA;AAAA,IAMjB,OAAwC;AAEtC,UAAI,KAAK,QAAQ,SAAS,GAAG;AAC3B,cAAM,QAAQ,KAAK,QAAQ;AAC3B,YAAI,iBAAiB,OAAO;AAC1B,iBAAO,QAAQ,OAAO;AAAA;AAExB,eAAO,QAAQ,QAAQ,EAAC,MAAM,OAAO;AAAA;AAIvC,UAAI,KAAK,SAAS;AAChB,YAAI,KAAK,U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
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/worker-utils",
|
|
3
|
-
"version": "3.3.0-alpha.
|
|
3
|
+
"version": "3.3.0-alpha.5",
|
|
4
4
|
"description": "Utilities for running tasks on worker threads",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@babel/runtime": "^7.3.1"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "d2df3bead97710c45fd2974cd51ecd7d5f7f5ea4"
|
|
53
53
|
}
|
|
@@ -71,8 +71,12 @@ export function getTransferListForWriter(object: object | null): object {
|
|
|
71
71
|
const clone = Object.assign({}, object);
|
|
72
72
|
|
|
73
73
|
Object.keys(clone).forEach((key) => {
|
|
74
|
-
//
|
|
75
|
-
if (
|
|
74
|
+
// Typed Arrays and Arrays are passed with no change
|
|
75
|
+
if (
|
|
76
|
+
typeof object[key] === 'object' &&
|
|
77
|
+
!ArrayBuffer.isView(object[key]) &&
|
|
78
|
+
!(object[key] instanceof Array)
|
|
79
|
+
) {
|
|
76
80
|
clone[key] = getTransferListForWriter(object[key]);
|
|
77
81
|
} else if (typeof clone[key] === 'function' || clone[key] instanceof RegExp) {
|
|
78
82
|
clone[key] = {};
|