@loaders.gl/worker-utils 3.1.0-alpha.2 → 4.0.0-alpha.3
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/lib/env-utils/version.js +2 -2
- package/dist/lib/env-utils/version.js.map +1 -1
- package/dist/lib/library-utils/library-utils.js +5 -5
- package/dist/lib/library-utils/library-utils.js.map +1 -1
- package/dist/lib/node/require-utils.node.js +6 -10
- package/dist/lib/node/require-utils.node.js.map +1 -1
- package/dist/lib/process-utils/child-process-proxy.js +5 -5
- package/dist/lib/process-utils/child-process-proxy.js.map +1 -1
- package/dist/lib/worker-api/create-worker.js +1 -1
- package/dist/lib/worker-api/create-worker.js.map +1 -1
- package/dist/lib/worker-api/get-worker-url.js +7 -7
- package/dist/lib/worker-api/get-worker-url.js.map +1 -1
- package/dist/lib/worker-api/process-on-worker.js +2 -2
- package/dist/lib/worker-api/process-on-worker.js.map +1 -1
- package/dist/lib/worker-farm/worker-body.js.map +1 -1
- package/dist/lib/worker-farm/worker-job.js.map +1 -1
- package/dist/lib/worker-farm/worker-pool.js +1 -1
- package/dist/lib/worker-farm/worker-pool.js.map +1 -1
- package/dist/lib/worker-farm/worker-thread.js +3 -3
- package/dist/lib/worker-farm/worker-thread.js.map +1 -1
- package/dist/lib/worker-utils/get-loadable-worker-url.js +1 -7
- package/dist/lib/worker-utils/get-loadable-worker-url.js.map +1 -1
- package/dist/lib/worker-utils/get-transfer-list.js.map +1 -1
- package/dist/lib/worker-utils/remove-nontransferable-options.js.map +1 -1
- package/dist/null-worker.js +4 -4
- package/dist/null-worker.js.map +1 -1
- package/package.json +4 -4
- package/src/lib/env-utils/version.ts +1 -1
- package/src/lib/library-utils/library-utils.ts +6 -4
- package/src/lib/node/{require-utils.node.js → require-utils.node.ts} +13 -9
- package/src/lib/process-utils/child-process-proxy.ts +1 -1
- package/src/lib/worker-api/create-worker.ts +11 -7
- package/src/lib/worker-api/process-on-worker.ts +1 -1
- package/src/lib/worker-farm/worker-body.ts +2 -2
- package/src/lib/worker-farm/worker-job.ts +2 -2
- package/src/lib/worker-farm/worker-thread.ts +2 -2
- package/src/lib/worker-utils/get-transfer-list.ts +1 -1
- package/src/lib/worker-utils/remove-nontransferable-options.ts +1 -1
- package/src/types.ts +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const DEFAULT_VERSION = 'beta';
|
|
2
|
-
export const VERSION = typeof "
|
|
2
|
+
export const VERSION = typeof "4.0.0-alpha.3" !== 'undefined' ? "4.0.0-alpha.3" : DEFAULT_VERSION;
|
|
3
3
|
|
|
4
|
-
if (typeof "
|
|
4
|
+
if (typeof "4.0.0-alpha.3" === '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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/env-utils/version.ts"],"names":["DEFAULT_VERSION","VERSION","console","error"],"mappings":"AAIA,MAAMA,eAAe,GAAG,MAAxB;AAEA,OAAO,MAAMC,OAAO,GAAG,2BAAuB,WAAvB,qBAAmDD,eAAnE;;AACP,IAAI,2BAAuB,WAA3B,EAAwC;AAEtCE,EAAAA,OAAO,CAACC,KAAR,CACE,iIADF;AAGD","sourcesContent":["// Version constant cannot be imported, it needs to correspond to the build version of **this** module.\n// __VERSION__ is injected by babel-plugin-version-inline\n\n// Change to `latest` on production branches\nconst DEFAULT_VERSION = 'beta';\ndeclare let __VERSION__;\nexport const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : DEFAULT_VERSION;\nif (typeof __VERSION__ === 'undefined') {\n // eslint-disable-next-line\n console.error(\n 'loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.'\n );\n}\n"],"file":"version.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/env-utils/version.ts"],"names":["DEFAULT_VERSION","VERSION","console","error"],"mappings":"AAIA,MAAMA,eAAe,GAAG,MAAxB;AAEA,OAAO,MAAMC,OAAO,GAAG,2BAAuB,WAAvB,qBAAmDD,eAAnE;;AACP,IAAI,2BAAuB,WAA3B,EAAwC;AAEtCE,EAAAA,OAAO,CAACC,KAAR,CACE,iIADF;AAGD","sourcesContent":["// Version constant cannot be imported, it needs to correspond to the build version of **this** module.\n// __VERSION__ is injected by babel-plugin-version-inline\n\n// Change to `latest` on production branches\nconst DEFAULT_VERSION = 'beta';\ndeclare let __VERSION__: string;\nexport const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : DEFAULT_VERSION;\nif (typeof __VERSION__ === 'undefined') {\n // eslint-disable-next-line\n console.error(\n 'loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.'\n );\n}\n"],"file":"version.js"}
|
|
@@ -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 "
|
|
6
|
+
const VERSION = typeof "4.0.0-alpha.3" !== 'undefined' ? "4.0.0-alpha.3" : LATEST;
|
|
7
7
|
const loadLibraryPromises = {};
|
|
8
8
|
export async function loadLibrary(libraryUrl, moduleName = null, options = {}) {
|
|
9
9
|
if (moduleName) {
|
|
@@ -25,19 +25,19 @@ export function getLibraryUrl(library, moduleName, options) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
if (!isBrowser) {
|
|
28
|
-
return
|
|
28
|
+
return "modules/".concat(moduleName, "/dist/libs/").concat(library);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
if (options.CDN) {
|
|
32
32
|
assert(options.CDN.startsWith('http'));
|
|
33
|
-
return
|
|
33
|
+
return "".concat(options.CDN, "/").concat(moduleName, "@").concat(VERSION, "/dist/libs/").concat(library);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
if (isWorker) {
|
|
37
|
-
return
|
|
37
|
+
return "../src/libs/".concat(library);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
return
|
|
40
|
+
return "modules/".concat(moduleName, "/src/libs/").concat(library);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
async function loadLibraryFromFile(libraryUrl) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/library-utils/library-utils.ts"],"names":["global","isBrowser","isWorker","node","assert","VERSION","__VERSION__","LATEST","loadLibraryPromises","loadLibrary","libraryUrl","moduleName","options","getLibraryUrl","loadLibraryFromFile","library","startsWith","modules","CDN","endsWith","response","fetch","arrayBuffer","requireFromFile","importScripts","scriptSource","text","loadLibraryFromString","id","requireFromString","eval","call","script","document","createElement","appendChild","createTextNode","e","body"],"mappings":"AACA,SAAQA,MAAR,EAAgBC,SAAhB,EAA2BC,QAA3B,QAA0C,sBAA1C;AACA,OAAO,KAAKC,IAAZ,MAAsB,4BAAtB;AACA,SAAQC,MAAR,QAAqB,qBAArB;AACA,SAAQC,OAAO,IAAIC,WAAnB,QAAqC,sBAArC;AAGA,MAAMC,MAAM,GAAG,MAAf;AACA,MAAMF,OAAO,GAAG,2BAAuB,WAAvB,qBAAmDE,MAAnE;AAEA,MAAMC,
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/library-utils/library-utils.ts"],"names":["global","isBrowser","isWorker","node","assert","VERSION","__VERSION__","LATEST","loadLibraryPromises","loadLibrary","libraryUrl","moduleName","options","getLibraryUrl","loadLibraryFromFile","library","startsWith","modules","CDN","endsWith","response","fetch","arrayBuffer","requireFromFile","importScripts","scriptSource","text","loadLibraryFromString","id","requireFromString","eval","call","script","document","createElement","appendChild","createTextNode","e","body"],"mappings":"AACA,SAAQA,MAAR,EAAgBC,SAAhB,EAA2BC,QAA3B,QAA0C,sBAA1C;AACA,OAAO,KAAKC,IAAZ,MAAsB,4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GAAcD,YAAd;AACD;;AACDQ,EAAAA,QAAQ,CAACK,IAAT,CAAcH,WAAd,CAA0BH,MAA1B;AACA,SAAO,IAAP;AACD","sourcesContent":["/* global importScripts */\nimport {global, isBrowser, isWorker} from '../env-utils/globals';\nimport * as node from '../node/require-utils.node';\nimport {assert} from '../env-utils/assert';\nimport {VERSION as __VERSION__} from '../env-utils/version';\n\n// TODO - unpkg.com doesn't seem to have a `latest` specifier for alpha releases...\nconst LATEST = 'beta';\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : LATEST;\n\nconst loadLibraryPromises: Record<string, Promise<any>> = {}; // promises\n\n/**\n * Dynamically loads a library (\"module\")\n *\n * - wasm library: Array buffer is returned\n * - js library: Parse JS is returned\n *\n * Method depends on environment\n * - browser - script element is created and installed on document\n * - worker - eval is called on global context\n * - node - file is required\n *\n * @param libraryUrl\n * @param moduleName\n * @param options\n */\nexport async function loadLibrary(\n libraryUrl: string,\n moduleName: string | null = null,\n options: object = {}\n): Promise<any> {\n if (moduleName) {\n libraryUrl = getLibraryUrl(libraryUrl, moduleName, options);\n }\n\n // Ensure libraries are only loaded once\n\n loadLibraryPromises[libraryUrl] =\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n loadLibraryPromises[libraryUrl] || loadLibraryFromFile(libraryUrl);\n return await loadLibraryPromises[libraryUrl];\n}\n\n// TODO - sort out how to resolve paths for main/worker and dev/prod\nexport function getLibraryUrl(library: string, moduleName?: string, options?: any): string {\n // Check if already a URL\n if (library.startsWith('http')) {\n return library;\n }\n\n // Allow application to import and supply libraries through `options.modules`\n const modules = options.modules || {};\n if (modules[library]) {\n return modules[library];\n }\n\n // Load from local files, not from CDN scripts in Node.js\n // TODO - needs to locate the modules directory when installed!\n if (!isBrowser) {\n return `modules/${moduleName}/dist/libs/${library}`;\n }\n\n // In browser, load from external scripts\n if (options.CDN) {\n assert(options.CDN.startsWith('http'));\n return `${options.CDN}/${moduleName}@${VERSION}/dist/libs/${library}`;\n }\n\n // TODO - loading inside workers requires paths relative to worker script location...\n if (isWorker) {\n return `../src/libs/${library}`;\n }\n\n return `modules/${moduleName}/src/libs/${library}`;\n}\n\nasync function loadLibraryFromFile(libraryUrl: string): Promise<any> {\n if (libraryUrl.endsWith('wasm')) {\n const response = await fetch(libraryUrl);\n return await response.arrayBuffer();\n }\n\n if (!isBrowser) {\n return node.requireFromFile && (await node.requireFromFile(libraryUrl));\n }\n if (isWorker) {\n return importScripts(libraryUrl);\n }\n // TODO - fix - should be more secure than string parsing since observes CORS\n // if (isBrowser) {\n // return await loadScriptFromFile(libraryUrl);\n // }\n\n const response = await fetch(libraryUrl);\n const scriptSource = await response.text();\n return loadLibraryFromString(scriptSource, libraryUrl);\n}\n\n/*\nasync function loadScriptFromFile(libraryUrl) {\n const script = document.createElement('script');\n script.src = libraryUrl;\n return await new Promise((resolve, reject) => {\n script.onload = data => {\n resolve(data);\n };\n script.onerror = reject;\n });\n}\n*/\n\n// TODO - Needs security audit...\n// - Raw eval call\n// - Potentially bypasses CORS\n// Upside is that this separates fetching and parsing\n// we could create a`LibraryLoader` or`ModuleLoader`\nfunction loadLibraryFromString(scriptSource: string, id: string): null | any {\n if (!isBrowser) {\n return node.requireFromString && node.requireFromString(scriptSource, id);\n }\n\n if (isWorker) {\n // Use lvalue trick to make eval run in global scope\n eval.call(global, scriptSource); // eslint-disable-line no-eval\n // https://stackoverflow.com/questions/9107240/1-evalthis-vs-evalthis-in-javascript\n // http://perfectionkills.com/global-eval-what-are-the-options/\n return null;\n }\n\n const script = document.createElement('script');\n script.id = id;\n // most browsers like a separate text node but some throw an error. The second method covers those.\n try {\n script.appendChild(document.createTextNode(scriptSource));\n } catch (e) {\n script.text = scriptSource;\n }\n document.body.appendChild(script);\n return null;\n}\n\n// TODO - technique for module injection into worker, from THREE.DracoLoader...\n/*\nfunction combineWorkerWithLibrary(worker, jsContent) {\n var fn = wWorker.toString();\n var body = [\n '// injected',\n jsContent,\n '',\n '// worker',\n fn.substring(fn.indexOf('{') + 1, fn.lastIndexOf('}'))\n ].join('\\n');\n this.workerSourceURL = URL.createObjectURL(new Blob([body]));\n}\n*/\n"],"file":"library-utils.js"}
|
|
@@ -8,25 +8,21 @@ export async function requireFromFile(filename) {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
if (!filename.startsWith('/')) {
|
|
11
|
-
filename =
|
|
11
|
+
filename = "".concat(process.cwd(), "/").concat(filename);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
return require(filename);
|
|
15
15
|
}
|
|
16
|
-
export function requireFromString(code, filename = '', options
|
|
16
|
+
export function requireFromString(code, filename = '', options) {
|
|
17
|
+
var _options, _options2;
|
|
18
|
+
|
|
17
19
|
if (typeof filename === 'object') {
|
|
18
20
|
options = filename;
|
|
19
21
|
filename = '';
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
options = {
|
|
23
|
-
appendPaths: [],
|
|
24
|
-
prependPaths: [],
|
|
25
|
-
...options
|
|
26
|
-
};
|
|
27
|
-
|
|
28
24
|
if (typeof code !== 'string') {
|
|
29
|
-
throw new Error(
|
|
25
|
+
throw new Error("code must be a string, not ".concat(typeof code));
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
const paths = Module._nodeModulePaths(path.dirname(filename));
|
|
@@ -34,7 +30,7 @@ export function requireFromString(code, filename = '', options = {}) {
|
|
|
34
30
|
const parent = module.parent;
|
|
35
31
|
const newModule = new Module(filename, parent);
|
|
36
32
|
newModule.filename = filename;
|
|
37
|
-
newModule.paths = [].concat(options.prependPaths).concat(paths).concat(options.appendPaths);
|
|
33
|
+
newModule.paths = [].concat(((_options = options) === null || _options === void 0 ? void 0 : _options.prependPaths) || []).concat(paths).concat(((_options2 = options) === null || _options2 === void 0 ? void 0 : _options2.appendPaths) || []);
|
|
38
34
|
|
|
39
35
|
newModule._compile(code, filename);
|
|
40
36
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/node/require-utils.node.
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/node/require-utils.node.ts"],"names":["Module","path","requireFromFile","filename","startsWith","response","fetch","code","text","requireFromString","process","cwd","require","options","Error","paths","_nodeModulePaths","dirname","parent","module","newModule","concat","prependPaths","appendPaths","_compile","children","splice","indexOf","exports"],"mappings":"AAMA,OAAOA,MAAP,MAAmB,QAAnB;AACA,OAAOC,IAAP,MAAiB,MAAjB;AAMA,OAAO,eAAeC,eAAf,CAA+BC,QAA/B,EAA+D;AACpE,MAAIA,QAAQ,CAACC,UAAT,CAAoB,MAApB,CAAJ,EAAiC;AAC/B,UAAMC,QAAQ,GAAG,MAAMC,KAAK,CAACH,QAAD,CAA5B;AACA,UAAMI,IAAI,GAAG,MAAMF,QAAQ,CAACG,IAAT,EAAnB;AACA,WAAOC,iBAAiB,CAACF,IAAD,CAAxB;AACD;;AAED,MAAI,CAACJ,QAAQ,CAACC,UAAT,CAAoB,GAApB,CAAL,EAA+B;AAC7BD,IAAAA,QAAQ,aAAMO,OAAO,CAACC,GAAR,EAAN,cAAuBR,QAAvB,CAAR;AACD;;AACD,SAAOS,OAAO,CAACT,QAAD,CAAd;AACD;AAQD,OAAO,SAASM,iBAAT,CACLF,IADK,EAELJ,QAAQ,GAAG,EAFN,EAGLU,OAHK,EAOA;AAAA;;AACL,MAAI,OAAOV,QAAP,KAAoB,QAAxB,EAAkC;AAChCU,IAAAA,OAAO,GAAGV,QAAV;AACAA,IAAAA,QAAQ,GAAG,EAAX;AACD;;AAED,MAAI,OAAOI,IAAP,KAAgB,QAApB,EAA8B;AAC5B,UAAM,IAAIO,KAAJ,sCAAwC,OAAOP,IAA/C,EAAN;AACD;;AAGD,QAAMQ,KAAK,GAAGf,MAAM,CAACgB,gBAAP,CAAwBf,IAAI,CAACgB,OAAL,CAAad,QAAb,CAAxB,CAAd;;AAEA,QAAMe,MAAM,GAAGC,MAAM,CAACD,MAAtB;AAEA,QAAME,SAAS,GAAG,IAAIpB,MAAJ,CAAWG,QAAX,EAAqBe,MAArB,CAAlB;AACAE,EAAAA,SAAS,CAACjB,QAAV,GAAqBA,QAArB;AACAiB,EAAAA,SAAS,CAACL,KAAV,GAAmB,EAAD,CACfM,MADe,CACR,aAAAR,OAAO,UAAP,4CAASS,YAAT,KAAyB,EADjB,EAEfD,MAFe,CAERN,KAFQ,EAGfM,MAHe,CAGR,cAAAR,OAAO,UAAP,8CAASU,WAAT,KAAwB,EAHhB,CAAlB;;AAKAH,EAAAA,SAAS,CAACI,QAAV,CAAmBjB,IAAnB,EAAyBJ,QAAzB;;AAEA,MAAIe,MAAM,IAAIA,MAAM,CAACO,QAArB,EAA+B;AAC7BP,IAAAA,MAAM,CAACO,QAAP,CAAgBC,MAAhB,CAAuBR,MAAM,CAACO,QAAP,CAAgBE,OAAhB,CAAwBP,SAAxB,CAAvB,EAA2D,CAA3D;AACD;;AAED,SAAOA,SAAS,CAACQ,OAAjB;AACD","sourcesContent":["// Fork of https://github.com/floatdrop/require-from-string/blob/master/index.js\n// Copyright (c) Vsevolod Strukchinsky <floatdrop@gmail.com> (github.com/floatdrop)\n// MIT license\n\n// this file is not visible to webpack (it is excluded in the package.json \"browser\" field).\n\nimport Module from 'module';\nimport path from 'path';\n\n// Node.js Dynamically require from file\n// Relative names are resolved relative to cwd\n// This indirect function is provided because webpack will try to bundle `module.require`.\n// this file is not visible to webpack (it is excluded in the package.json \"browser\" field).\nexport async function requireFromFile(filename: string): Promise<any> {\n if (filename.startsWith('http')) {\n const response = await fetch(filename);\n const code = await response.text();\n return requireFromString(code);\n }\n\n if (!filename.startsWith('/')) {\n filename = `${process.cwd()}/${filename}`;\n }\n return require(filename);\n}\n\n// Dynamically require from string\n// - `code` - Required - Type: string - Module code.\n// - `filename` - Type: string - Default: '' - Optional filename.\n// - `options.appendPaths` Type: Array List of paths, that will be appended to module paths.\n// Useful, when you want to be able require modules from these paths.\n// - `options.prependPaths` Type: Array Same as appendPaths, but paths will be prepended.\nexport function requireFromString(\n code: string,\n filename = '',\n options?: {\n prependPaths?: string[];\n appendPaths?: string[];\n }\n): any {\n if (typeof filename === 'object') {\n options = filename;\n filename = '';\n }\n\n if (typeof code !== 'string') {\n throw new Error(`code must be a string, not ${typeof code}`);\n }\n\n // @ts-ignore\n const paths = Module._nodeModulePaths(path.dirname(filename));\n\n const parent = module.parent;\n // @ts-ignore\n const newModule = new Module(filename, parent);\n newModule.filename = filename;\n newModule.paths = ([] as string[])\n .concat(options?.prependPaths || [])\n .concat(paths)\n .concat(options?.appendPaths || []);\n // @ts-ignore\n newModule._compile(code, filename);\n\n if (parent && parent.children) {\n parent.children.splice(parent.children.indexOf(newModule), 1);\n }\n\n return newModule.exports;\n}\n"],"file":"require-utils.node.js"}
|
|
@@ -8,7 +8,7 @@ const DEFAULT_PROPS = {
|
|
|
8
8
|
autoPort: true,
|
|
9
9
|
wait: 2000,
|
|
10
10
|
onSuccess: processProxy => {
|
|
11
|
-
console.log(
|
|
11
|
+
console.log("Started ".concat(processProxy.props.command));
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
14
|
export default class ChildProcessProxy {
|
|
@@ -55,28 +55,28 @@ export default class ChildProcessProxy {
|
|
|
55
55
|
resolve({});
|
|
56
56
|
});
|
|
57
57
|
|
|
58
|
-
console.log(
|
|
58
|
+
console.log("Spawning ".concat(props.command, " ").concat(props.arguments.join(' ')));
|
|
59
59
|
const childProcess = ChildProcess.spawn(props.command, args, props.spawn);
|
|
60
60
|
this.childProcess = childProcess;
|
|
61
61
|
childProcess.stdout.on('data', data => {
|
|
62
62
|
console.log(data.toString());
|
|
63
63
|
});
|
|
64
64
|
childProcess.stderr.on('data', data => {
|
|
65
|
-
console.log(
|
|
65
|
+
console.log("Child process wrote to stderr: \"".concat(data, "\"."));
|
|
66
66
|
|
|
67
67
|
this._clearTimeout();
|
|
68
68
|
|
|
69
69
|
reject(new Error(data));
|
|
70
70
|
});
|
|
71
71
|
childProcess.on('error', error => {
|
|
72
|
-
console.log(
|
|
72
|
+
console.log("Child process errored with ".concat(error));
|
|
73
73
|
|
|
74
74
|
this._clearTimeout();
|
|
75
75
|
|
|
76
76
|
reject(error);
|
|
77
77
|
});
|
|
78
78
|
childProcess.on('close', code => {
|
|
79
|
-
console.log(
|
|
79
|
+
console.log("Child process exited with ".concat(code));
|
|
80
80
|
this.childProcess = null;
|
|
81
81
|
|
|
82
82
|
this._clearTimeout();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/process-utils/child-process-proxy.ts"],"names":["ChildProcess","getAvailablePort","DEFAULT_PROPS","command","arguments","port","autoPort","wait","onSuccess","processProxy","console","log","props","ChildProcessProxy","constructor","id","start","args","Number","portArg","push","String","Promise","resolve","reject","_setTimeout","join","childProcess","spawn","stdout","on","data","toString","stderr","_clearTimeout","Error","error","code","stop","kill","exit","statusCode","process","message","callback","successTimer","setTimeout","clearTimeout"],"mappings":";AAIA,OAAO,KAAKA,YAAZ,MAA8B,eAA9B;AACA,SAAQC,gBAAR,QAA+B,iBAA/B;AAqBA,MAAMC,aAAqC,GAAG;AAC5CC,EAAAA,OAAO,EAAE,EADmC;AAE5CC,EAAAA,SAAS,EAAE,EAFiC;AAG5CC,EAAAA,IAAI,EAAE,IAHsC;AAI5CC,EAAAA,QAAQ,EAAE,IAJkC;AAK5CC,EAAAA,IAAI,EAAE,IALsC;AAM5CC,EAAAA,SAAS,EAAGC,YAAD,IAAkB;AAC3BC,IAAAA,OAAO,CAACC,GAAR,
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/process-utils/child-process-proxy.ts"],"names":["ChildProcess","getAvailablePort","DEFAULT_PROPS","command","arguments","port","autoPort","wait","onSuccess","processProxy","console","log","props","ChildProcessProxy","constructor","id","start","args","Number","portArg","push","String","Promise","resolve","reject","_setTimeout","join","childProcess","spawn","stdout","on","data","toString","stderr","_clearTimeout","Error","error","code","stop","kill","exit","statusCode","process","message","callback","successTimer","setTimeout","clearTimeout"],"mappings":";AAIA,OAAO,KAAKA,YAAZ,MAA8B,eAA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,OAAO,CAAC,EAAD,CAAP;AACD,SALD;AAMD,OAhCD,CAgCE,OAAOa,KAAP,EAAc;AACdZ,QAAAA,MAAM,CAACY,KAAD,CAAN;AACD;AACF,KApCY,CAAb;AAqCD;;AAGS,QAAJE,IAAI,GAAkB;AAC1B,QAAI,KAAKX,YAAT,EAAuB;AACrB,WAAKA,YAAL,CAAkBY,IAAlB;AACA,WAAKZ,YAAL,GAAoB,IAApB;AACD;AACF;;AAGS,QAAJa,IAAI,CAACC,UAAkB,GAAG,CAAtB,EAAwC;AAChD,QAAI;AACF,YAAM,KAAKH,IAAL,EAAN;AAEAI,MAAAA,OAAO,CAACF,IAAR,CAAaC,UAAb;AACD,KAJD,CAIE,OAAOL,KAAP,EAAc;AACd1B,MAAAA,OAAO,CAAC0B,KAAR,CAAeA,KAAD,CAAiBO,OAAjB,IAA4BP,KAA1C;AAEAM,MAAAA,OAAO,CAACF,IAAR,CAAa,CAAb;AACD;AACF;;AAEDf,EAAAA,WAAW,CAACmB,QAAD,EAAqC;AAC9C,QAAI1B,MAAM,CAAC,KAAKN,KAAL,CAAWL,IAAZ,CAAN,GAA0B,CAA9B,EAAiC;AAC/B,WAAKsC,YAAL,GAAoBC,UAAU,CAACF,QAAD,EAAW,KAAKhC,KAAL,CAAWL,IAAtB,CAA9B;AACD;AACF;;AAED2B,EAAAA,aAAa,GAAG;AACd,QAAI,KAAKW,YAAT,EAAuB;AACrBE,MAAAA,YAAY,CAAC,KAAKF,YAAN,CAAZ;AACD;AACF;;AAlGoC","sourcesContent":["/* eslint-disable no-console */\n// Avoid using named imports for Node builtins to help with \"empty\" resolution\n// for bundlers targeting browser environments. Access imports & types\n// through the `ChildProcess` object (e.g. `ChildProcess.spawn`, `ChildProcess.ChildProcess`).\nimport * as ChildProcess from 'child_process';\nimport {getAvailablePort} from './process-utils';\n\nexport type ChildProcessProxyProps = {\n command: string;\n arguments: string[];\n /** Whether to add a port specified arg */\n portArg?: string;\n /** Base port number */\n port?: number;\n /** Whether to search for an available port if the base port is occupied */\n autoPort?: boolean;\n /** Number of milliseconds to wait until concluding success */\n /** wait: 0 - infinity */\n wait?: number;\n /** Options passed on to Node'.js `spawn` */\n spawn?: ChildProcess.SpawnOptionsWithoutStdio;\n /** Callback when the */\n onStart?: (proxy: ChildProcessProxy) => void;\n onSuccess?: (proxy: ChildProcessProxy) => void;\n};\n\nconst DEFAULT_PROPS: ChildProcessProxyProps = {\n command: '',\n arguments: [],\n port: 5000,\n autoPort: true,\n wait: 2000,\n onSuccess: (processProxy) => {\n console.log(`Started ${processProxy.props.command}`);\n }\n};\n\n/**\n * Manager for a Node.js child process\n * Prepares arguments, starts, stops and tracks output\n */\nexport default class ChildProcessProxy {\n id: string;\n props: ChildProcessProxyProps = {...DEFAULT_PROPS};\n private childProcess: ChildProcess.ChildProcess | null = null;\n private port: number = 0;\n private successTimer?: any; // NodeJS.Timeout;\n\n // constructor(props?: {id?: string});\n constructor({id = 'browser-driver'} = {}) {\n this.id = id;\n }\n\n /** Starts a child process with the provided props */\n async start(props: ChildProcessProxyProps): Promise<object> {\n props = {...DEFAULT_PROPS, ...props};\n this.props = props;\n\n const args = [...props.arguments];\n\n // If portArg is set, we can look up an available port\n this.port = Number(props.port);\n if (props.portArg) {\n if (props.autoPort) {\n this.port = await getAvailablePort(props.port);\n }\n args.push(props.portArg, String(this.port));\n }\n\n return await new Promise((resolve, reject) => {\n try {\n this._setTimeout(() => {\n if (props.onSuccess) {\n props.onSuccess(this);\n }\n resolve({});\n });\n\n console.log(`Spawning ${props.command} ${props.arguments.join(' ')}`);\n const childProcess = ChildProcess.spawn(props.command, args, props.spawn);\n this.childProcess = childProcess;\n\n childProcess.stdout.on('data', (data) => {\n console.log(data.toString());\n });\n // TODO - add option regarding whether stderr should be treated as data\n childProcess.stderr.on('data', (data) => {\n console.log(`Child process wrote to stderr: \"${data}\".`);\n this._clearTimeout();\n reject(new Error(data));\n });\n childProcess.on('error', (error) => {\n console.log(`Child process errored with ${error}`);\n this._clearTimeout();\n reject(error);\n });\n childProcess.on('close', (code) => {\n console.log(`Child process exited with ${code}`);\n this.childProcess = null;\n this._clearTimeout();\n resolve({});\n });\n } catch (error) {\n reject(error);\n }\n });\n }\n\n /** Stops a running child process */\n async stop(): Promise<void> {\n if (this.childProcess) {\n this.childProcess.kill();\n this.childProcess = null;\n }\n }\n\n /** Exits this process */\n async exit(statusCode: number = 0): Promise<void> {\n try {\n await this.stop();\n // eslint-disable-next-line no-process-exit\n process.exit(statusCode);\n } catch (error) {\n console.error((error as Error).message || error);\n // eslint-disable-next-line no-process-exit\n process.exit(1);\n }\n }\n\n _setTimeout(callback: (...args: any[]) => void) {\n if (Number(this.props.wait) > 0) {\n this.successTimer = setTimeout(callback, this.props.wait);\n }\n }\n\n _clearTimeout() {\n if (this.successTimer) {\n clearTimeout(this.successTimer);\n }\n }\n}\n"],"file":"child-process-proxy.js"}
|
|
@@ -33,7 +33,7 @@ export function createWorker(process, processInBatches) {
|
|
|
33
33
|
|
|
34
34
|
inputBatches = new AsyncQueue();
|
|
35
35
|
options = payload.options || {};
|
|
36
|
-
const resultIterator = processInBatches(inputBatches, options, context
|
|
36
|
+
const resultIterator = processInBatches(inputBatches, options, context);
|
|
37
37
|
|
|
38
38
|
for await (const batch of resultIterator) {
|
|
39
39
|
WorkerBody.postMessage('output-batch', {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/worker-api/create-worker.ts"],"names":["AsyncQueue","WorkerBody","requestId","inputBatches","options","createWorker","process","processInBatches","self","context","processOnMainThread","onmessage","type","payload","Error","result","input","postMessage","resultIterator","batch","push","close","error","message","arrayBuffer","Promise","resolve","reject","id","onMessage","removeEventListener","addEventListener"],"mappings":"AAOA,OAAOA,UAAP,MAAuB,4BAAvB;AACA,OAAOC,UAAP,MAAuB,4BAAvB;AAIA,IAAIC,SAAS,GAAG,CAAhB;AACA,IAAIC,YAAJ;AACA,IAAIC,OAAJ;
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/worker-api/create-worker.ts"],"names":["AsyncQueue","WorkerBody","requestId","inputBatches","options","createWorker","process","processInBatches","self","context","processOnMainThread","onmessage","type","payload","Error","result","input","postMessage","resultIterator","batch","push","close","error","message","arrayBuffer","Promise","resolve","reject","id","onMessage","removeEventListener","addEventListener"],"mappings":"AAOA,OAAOA,UAAP,MAAuB,4BAAvB;AACA,OAAOC,UAAP,MAAuB,4BAAvB;AAIA,IAAIC,SAAS,GAAG,CAAhB;AACA,IAAIC,YAAJ;AACA,IAAIC,OAAJ;AAWA,OAAO,SAASC,YAAT,CAAsBC,OAAtB,EAAwCC,gBAAxC,EAAmF;AAExF,MAAI,OAAOC,IAAP,KAAgB,WAApB,EAAiC;AAC/B;AACD;;AAED,QAAMC,OAAsB,GAAG;AAC7BH,IAAAA,OAAO,EAAEI;AADoB,GAA/B;;AAKAT,EAAAA,UAAU,CAACU,SAAX,GAAuB,OAAOC,IAAP,EAAgCC,OAAhC,KAAkE;AACvF,QAAI;AACF,cAAQD,IAAR;AACE,aAAK,SAAL;AACE,cAAI,CAACN,OAAL,EAAc;AACZ,kBAAM,IAAIQ,KAAJ,CAAU,2CAAV,CAAN;AACD;;AACD,gBAAMC,MAAM,GAAG,MAAMT,OAAO,CAACO,OAAO,CAACG,KAAT,EAAgBH,OAAO,CAACT,OAAR,IAAmB,EAAnC,EAAuCK,OAAvC,CAA5B;AACAR,UAAAA,UAAU,CAACgB,WAAX,CAAuB,MAAvB,EAA+B;AAACF,YAAAA;AAAD,WAA/B;AACA;;AAEF,aAAK,oBAAL;AACE,cAAI,CAACR,gBAAL,EAAuB;AACrB,kBAAM,IAAIO,KAAJ,CAAU,4CAAV,CAAN;AACD;;AACDX,UAAAA,YAAY,GAAG,IAAIH,UAAJ,EAAf;AACAI,UAAAA,OAAO,GAAGS,OAAO,CAACT,OAAR,IAAmB,EAA7B;AACA,gBAAMc,cAAc,GAAGX,gBAAgB,CAACJ,YAAD,EAAeC,OAAf,EAAwBK,OAAxB,CAA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IAAAA,UAAU,CAAC8B,gBAAX,CAA4BF,SAA5B;AAGA,UAAMhB,OAAO,GAAG;AAACe,MAAAA,EAAD;AAAKZ,MAAAA,KAAK,EAAEQ,WAAZ;AAAyBpB,MAAAA;AAAzB,KAAhB;AACAH,IAAAA,UAAU,CAACgB,WAAX,CAAuB,SAAvB,EAAkCJ,OAAlC;AACD,GAhCM,CAAP;AAiCD","sourcesContent":["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 // 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<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"],"file":"create-worker.js"}
|
|
@@ -1,18 +1,18 @@
|
|
|
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 "
|
|
4
|
+
const VERSION = typeof "4.0.0-alpha.3" !== 'undefined' ? "4.0.0-alpha.3" : NPM_TAG;
|
|
5
5
|
export function getWorkerName(worker) {
|
|
6
|
-
const warning = worker.version !== VERSION ?
|
|
7
|
-
return
|
|
6
|
+
const warning = worker.version !== VERSION ? " (worker-utils@".concat(VERSION, ")") : '';
|
|
7
|
+
return "".concat(worker.name, "@").concat(worker.version).concat(warning);
|
|
8
8
|
}
|
|
9
9
|
export function getWorkerURL(worker, options = {}) {
|
|
10
10
|
const workerOptions = options[worker.id] || {};
|
|
11
|
-
const workerFile =
|
|
11
|
+
const workerFile = "".concat(worker.id, "-worker.js");
|
|
12
12
|
let url = workerOptions.workerUrl;
|
|
13
13
|
|
|
14
14
|
if (options._workerType === 'test') {
|
|
15
|
-
url =
|
|
15
|
+
url = "modules/".concat(worker.module, "/dist/").concat(workerFile);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
if (!url) {
|
|
@@ -22,8 +22,8 @@ export function getWorkerURL(worker, options = {}) {
|
|
|
22
22
|
version = NPM_TAG;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const versionTag = version ?
|
|
26
|
-
url =
|
|
25
|
+
const versionTag = version ? "@".concat(version) : '';
|
|
26
|
+
url = "https://unpkg.com/@loaders.gl/".concat(worker.module).concat(versionTag, "/dist/").concat(workerFile);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
assert(url);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/worker-api/get-worker-url.ts"],"names":["assert","VERSION","__VERSION__","NPM_TAG","getWorkerName","worker","warning","version","name","getWorkerURL","options","workerOptions","id","workerFile","url","workerUrl","_workerType","module","versionTag"],"mappings":"AACA,SAAQA,MAAR,QAAqB,qBAArB;AACA,SAAQC,OAAO,IAAIC,WAAnB,QAAqC,sBAArC;AAEA,MAAMC,OAAO,GAAG,MAAhB;AACA,MAAMF,OAAO,GAAG,2BAAuB,WAAvB,qBAAmDE,OAAnE;AAKA,OAAO,SAASC,aAAT,CAAuBC,MAAvB,EAAqD;AAC1D,QAAMC,OAAO,GAAGD,MAAM,CAACE,OAAP,KAAmBN,OAAnB,
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/worker-api/get-worker-url.ts"],"names":["assert","VERSION","__VERSION__","NPM_TAG","getWorkerName","worker","warning","version","name","getWorkerURL","options","workerOptions","id","workerFile","url","workerUrl","_workerType","module","versionTag"],"mappings":"AACA,SAAQA,MAAR,QAAqB,qBAArB;AACA,SAAQC,OAAO,IAAIC,WAAnB,QAAqC,sBAArC;AAEA,MAAMC,OAAO,GAAG,MAAhB;AACA,MAAMF,OAAO,GAAG,2BAAuB,WAAvB,qBAAmDE,OAAnE;AAKA,OAAO,SAASC,aAAT,CAAuBC,MAAvB,EAAqD;AAC1D,QAAMC,OAAO,GAAGD,MAAM,CAACE,OAAP,KAAmBN,OAAnB,4BAA+CA,OAA/C,SAA4D,EAA5E;AACA,mBAAUI,MAAM,CAACG,IAAjB,cAAyBH,MAAM,CAACE,OAAhC,SAA0CD,OAA1C;AACD;AASD,OAAO,SAASG,YAAT,CAAsBJ,MAAtB,EAA4CK,OAAsB,GAAG,EAArE,EAAiF;AACtF,QAAMC,aAAa,GAAGD,OAAO,CAACL,MAAM,CAACO,EAAR,CAAP,IAAsB,EAA5C;AAEA,QAAMC,UAAU,aAAMR,MAAM,CAACO,EAAb,eAAhB;AAEA,MAAIE,GAAG,GAAGH,aAAa,CAACI,SAAxB;;AAIA,MAAIL,OAAO,CAACM,WAAR,KAAwB,MAA5B,EAAoC;AAClCF,IAAAA,GAAG,qBAAcT,MAAM,CAACY,MAArB,mBAAoCJ,UAApC,CAAH;AACD;;AAGD,MAAI,CAACC,GAAL,EAAU;AAER,QAAIP,OAAO,GAAGF,MAAM,CAACE,OAArB;;AAEA,QAAIA,OAAO,KAAK,QAAhB,EAA0B;AAExBA,MAAAA,OAAO,GAAGJ,OAAV;AACD;;AACD,UAAMe,UAAU,GAAGX,OAAO,cAAOA,OAAP,IAAmB,EAA7C;AACAO,IAAAA,GAAG,2CAAoCT,MAAM,CAACY,MAA3C,SAAoDC,UAApD,mBAAuEL,UAAvE,CAAH;AACD;;AAEDb,EAAAA,MAAM,CAACc,GAAD,CAAN;AAGA,SAAOA,GAAP;AACD","sourcesContent":["import type {WorkerObject, WorkerOptions} from '../../types';\nimport {assert} from '../env-utils/assert';\nimport {VERSION as __VERSION__} from '../env-utils/version';\n\nconst NPM_TAG = 'beta'; // Change to 'latest' on release-branch\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : NPM_TAG;\n\n/**\n * Gets worker object's name (for debugging in Chrome thread inspector window)\n */\nexport function getWorkerName(worker: WorkerObject): string {\n const warning = worker.version !== VERSION ? ` (worker-utils@${VERSION})` : '';\n return `${worker.name}@${worker.version}${warning}`;\n}\n\n/**\n * Generate a worker URL based on worker object and options\n * @returns A URL to one of the following:\n * - a published worker on unpkg CDN\n * - a local test worker\n * - a URL provided by the user in options\n */\nexport function getWorkerURL(worker: WorkerObject, options: WorkerOptions = {}): string {\n const workerOptions = options[worker.id] || {};\n\n const workerFile = `${worker.id}-worker.js`;\n\n let url = workerOptions.workerUrl;\n\n // If URL is test, generate local loaders.gl url\n // @ts-ignore _workerType\n if (options._workerType === 'test') {\n url = `modules/${worker.module}/dist/${workerFile}`;\n }\n\n // If url override is not provided, generate a URL to published version on npm CDN unpkg.com\n if (!url) {\n // GENERATE\n let version = worker.version;\n // On master we need to load npm alpha releases published with the `beta` tag\n if (version === 'latest') {\n // throw new Error('latest worker version specified');\n version = NPM_TAG;\n }\n const versionTag = version ? `@${version}` : '';\n url = `https://unpkg.com/@loaders.gl/${worker.module}${versionTag}/dist/${workerFile}`;\n }\n\n assert(url);\n\n // Allow user to override location\n return url;\n}\n"],"file":"get-worker-url.js"}
|
|
@@ -34,7 +34,7 @@ async function onMessage(context, job, type, payload) {
|
|
|
34
34
|
break;
|
|
35
35
|
|
|
36
36
|
case 'error':
|
|
37
|
-
job.error(payload.error);
|
|
37
|
+
job.error(new Error(payload.error));
|
|
38
38
|
break;
|
|
39
39
|
|
|
40
40
|
case 'process':
|
|
@@ -69,7 +69,7 @@ async function onMessage(context, job, type, payload) {
|
|
|
69
69
|
break;
|
|
70
70
|
|
|
71
71
|
default:
|
|
72
|
-
console.warn(
|
|
72
|
+
console.warn("process-on-worker: unknown message ".concat(type));
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
//# sourceMappingURL=process-on-worker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/worker-api/process-on-worker.ts"],"names":["WorkerFarm","removeNontransferableOptions","getWorkerURL","getWorkerName","canProcessOnWorker","worker","options","isSupported","processOnWorker","data","context","name","url","workerFarm","getWorkerFarm","workerPool","getWorkerPool","jobName","job","startJob","onMessage","bind","transferableOptions","postMessage","input","result","type","payload","done","error","id","process","message","
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/worker-api/process-on-worker.ts"],"names":["WorkerFarm","removeNontransferableOptions","getWorkerURL","getWorkerName","canProcessOnWorker","worker","options","isSupported","processOnWorker","data","context","name","url","workerFarm","getWorkerFarm","workerPool","getWorkerPool","jobName","job","startJob","onMessage","bind","transferableOptions","postMessage","input","result","type","payload","done","error","Error","id","process","message","console","warn"],"mappings":"AAQA,OAAOA,UAAP,MAAuB,4BAAvB;AACA,SAAQC,4BAAR,QAA2C,gDAA3C;AACA,SAAQC,YAAR,EAAsBC,aAAtB,QAA0C,kBAA1C;AAaA,OAAO,SAASC,kBAAT,CAA4BC,MAA5B,EAAkDC,OAAlD,EAA2E;AAChF,MAAI,CAACN,UAAU,CAACO,WAAX,EAAL,EAA+B;AAC7B,WAAO,KAAP;AACD;;AAED,SAAOF,MAAM,CAACA,MAAP,KAAiBC,OAAjB,aAAiBA,OAAjB,uBAAiBA,OAAO,CAAED,MAA1B,CAAP;AACD;AAOD,OAAO,eAAeG,eAAf,CACLH,MADK,EAELI,IAFK,EAGLH,OAA+B,GAAG,EAH7B,EAILI,OAAsB,GAAG,EAJpB,EAKS;AACd,QAAMC,IAAI,GAAGR,aAAa,CAACE,MAAD,CAA1B;AACA,QAAMO,GAAG,GAAGV,YAAY,CAACG,MAAD,EAASC,OAAT,CAAxB;AAEA,QAAMO,UAAU,GAAGb,UAAU,CAACc,aAAX,CAAyBR,OAAzB,CAAnB;AACA,QAAMS,UAAU,GAAGF,UAAU,CAACG,aAAX,CAAyB;AAACL,IAAAA,IAAD;AAAOC,IAAAA;AAAP,GAAzB,CAAnB;AAEA,QAAMK,OAAO,GAAGX,OAAO,CAACW,OAAR,IAAmBZ,MAAM,CAACM,IAA1C;AACA,QAAMO,GAAG,GAAG,MAAMH,UAAU,CAACI,QAAX,CAChBF,OADgB,EAGhBG,SAAS,CAACC,IAAV,CAAe,IAAf,EAAqBX,OAArB,CAHgB,CAAlB;AAOA,QAAMY,mBAAmB,GAAGrB,4BAA4B,CAACK,OAAD,CAAxD;AACAY,EAAAA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MAAAA,OAAO,CAACC,IAAR,8CAAmDT,IAAnD;AA7BJ;AA+BD","sourcesContent":["import type {\n WorkerObject,\n WorkerOptions,\n WorkerContext,\n WorkerMessageType,\n WorkerMessagePayload\n} from '../../types';\nimport type WorkerJob from '../worker-farm/worker-job';\nimport WorkerFarm from '../worker-farm/worker-farm';\nimport {removeNontransferableOptions} from '../worker-utils/remove-nontransferable-options';\nimport {getWorkerURL, getWorkerName} from './get-worker-url';\n\ntype ProcessOnWorkerOptions = WorkerOptions & {\n jobName?: string;\n [key: string]: any;\n};\n\n/**\n * Determines if we can parse with worker\n * @param loader\n * @param data\n * @param options\n */\nexport function canProcessOnWorker(worker: WorkerObject, options?: WorkerOptions) {\n if (!WorkerFarm.isSupported()) {\n return false;\n }\n\n return worker.worker && options?.worker;\n}\n\n/**\n * This function expects that the worker thread sends certain messages,\n * Creating such a worker can be automated if the worker is wrapper by a call to\n * createWorker in @loaders.gl/worker-utils.\n */\nexport async function processOnWorker(\n worker: WorkerObject,\n data: any,\n options: ProcessOnWorkerOptions = {},\n context: WorkerContext = {}\n): Promise<any> {\n const name = getWorkerName(worker);\n const url = getWorkerURL(worker, options);\n\n const workerFarm = WorkerFarm.getWorkerFarm(options);\n const workerPool = workerFarm.getWorkerPool({name, url});\n\n const jobName = options.jobName || worker.name;\n const job = await workerPool.startJob(\n jobName,\n // eslint-disable-next-line\n onMessage.bind(null, context)\n );\n\n // Kick off the processing in the worker\n const transferableOptions = removeNontransferableOptions(options);\n job.postMessage('process', {input: data, options: transferableOptions});\n\n const result = await job.result;\n return result.result;\n}\n\n/**\n * Job completes when we receive the result\n * @param job\n * @param message\n */\nasync function onMessage(\n context: WorkerContext,\n job: WorkerJob,\n type: WorkerMessageType,\n payload: WorkerMessagePayload\n) {\n switch (type) {\n case 'done':\n // Worker is done\n job.done(payload);\n break;\n\n case 'error':\n // Worker encountered an error\n job.error(new Error(payload.error));\n break;\n\n case 'process':\n // Worker is asking for us (main thread) to process something\n const {id, input, options} = payload;\n try {\n if (!context.process) {\n job.postMessage('error', {id, error: 'Worker not set up to process on main thread'});\n return;\n }\n const result = await context.process(input, options);\n job.postMessage('done', {id, result});\n } catch (error) {\n const message = error instanceof Error ? error.message : 'unknown error';\n job.postMessage('error', {id, error: message});\n }\n break;\n\n default:\n // eslint-disable-next-line\n console.warn(`process-on-worker: unknown message ${type}`);\n }\n}\n"],"file":"process-on-worker.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/worker-farm/worker-body.ts"],"names":["getTransferList","onMessageWrapperMap","Map","WorkerBody","onmessage","onMessage","self","message","isKnownMessage","type","payload","data","addEventListener","onMessageWrapper","get","removeEventListener","delete","postMessage","source","transferList","startsWith"],"mappings":"AACA,SAAQA,eAAR,QAA8B,mCAA9B;AAEA,MAAMC,mBAAmB,GAAG,IAAIC,GAAJ,EAA5B;AAKA,eAAe,MAAMC,UAAN,CAAiB;AAIV,aAATC,SAAS,CAACC,SAAD,EAA6E;AAE/FC,IAAAA,IAAI,CAACF,SAAL,GAAkBG,OAAD,IAAa;AAC5B,UAAI,CAACC,cAAc,CAACD,OAAD,CAAnB,EAA8B;AAC5B;AACD;;AAGD,YAAM;AAACE,QAAAA,IAAD;AAAOC,QAAAA;AAAP,UAAkBH,OAAO,CAACI,IAAhC;AACAN,MAAAA,SAAS,CAACI,IAAD,EAAOC,OAAP,CAAT;AACD,KARD;AASD;;AAEsB,SAAhBE,gBAAgB,CACrBP,SADqB,EAErB;AACA,QAAIQ,gBAAgB,GAAGZ,mBAAmB,CAACa,GAApB,CAAwBT,SAAxB,CAAvB;;AAEA,QAAI,CAACQ,gBAAL,EAAuB;AACrBA,MAAAA,gBAAgB,GAAIN,OAAD,
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/worker-farm/worker-body.ts"],"names":["getTransferList","onMessageWrapperMap","Map","WorkerBody","onmessage","onMessage","self","message","isKnownMessage","type","payload","data","addEventListener","onMessageWrapper","get","removeEventListener","delete","postMessage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EAAU;AACR,YAAMK,IAAuB,GAAG;AAACO,QAAAA,MAAM,EAAE,YAAT;AAAuBT,QAAAA,IAAvB;AAA6BC,QAAAA;AAA7B,OAAhC;AACA,YAAMS,YAAY,GAAGnB,eAAe,CAACU,OAAD,CAApC;AAGAJ,MAAAA,IAAI,CAACW,WAAL,CAAiBN,IAAjB,EAAuBQ,YAAvB;AACD;AACF;;AA5D6B;;AAgEhC,SAASX,cAAT,CAAwBD,OAAxB,EAAoD;AAClD,QAAM;AAACE,IAAAA,IAAD;AAAOE,IAAAA;AAAP,MAAeJ,OAArB;AACA,SACEE,IAAI,KAAK,SAAT,IACAE,IADA,IAEA,OAAOA,IAAI,CAACO,MAAZ,KAAuB,QAFvB,IAGAP,IAAI,CAACO,MAAL,CAAYE,UAAZ,CAAuB,YAAvB,CAJF;AAMD","sourcesContent":["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: MessageEvent<any>) => {\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: 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"],"file":"worker-body.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/worker-farm/worker-job.ts"],"names":["assert","WorkerJob","constructor","jobName","workerThread","name","isRunning","_resolve","_reject","result","Promise","resolve","reject","postMessage","type","payload","source","done","value","error"],"mappings":";AAEA,SAAQA,MAAR,QAAqB,qBAArB;AAKA,eAAe,MAAMC,SAAN,CAAgB;AAU7BC,EAAAA,WAAW,CAACC,OAAD,EAAkBC,YAAlB,EAA8C;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AACvD,SAAKC,IAAL,GAAYF,OAAZ;AACA,SAAKC,YAAL,GAAoBA,YAApB;AACA,SAAKE,SAAL,GAAiB,IAAjB;;AACA,SAAKC,QAAL,GAAgB,MAAM,CAAE,CAAxB;;AACA,SAAKC,OAAL,GAAe,MAAM,CAAE,CAAvB;;AACA,SAAKC,MAAL,GAAc,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;AAC7C,WAAKL,QAAL,GAAgBI,OAAhB;AACA,WAAKH,OAAL,GAAeI,MAAf;AACD,KAHa,CAAd;AAID;;AAMDC,EAAAA,WAAW,CAACC,IAAD,EAA0BC,OAA1B,EAA+D;AACxE,SAAKX,YAAL,CAAkBS,WAAlB,CAA8B;AAC5BG,MAAAA,MAAM,EAAE,YADoB;AAE5BF,MAAAA,IAF4B;AAG5BC,MAAAA;AAH4B,KAA9B;AAKD;;AAKDE,EAAAA,IAAI,CAACC,KAAD,
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/worker-farm/worker-job.ts"],"names":["assert","WorkerJob","constructor","jobName","workerThread","name","isRunning","_resolve","_reject","result","Promise","resolve","reject","postMessage","type","payload","source","done","value","error"],"mappings":";AAEA,SAAQA,MAAR,QAAqB,qBAArB;AAKA,eAAe,MAAMC,SAAN,CAAgB;AAU7BC,EAAAA,WAAW,CAACC,OAAD,EAAkBC,YAAlB,EAA8C;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AACvD,SAAKC,IAAL,GAAYF,OAAZ;AACA,SAAKC,YAAL,GAAoBA,YAApB;AACA,SAAKE,SAAL,GAAiB,IAAjB;;AACA,SAAKC,QAAL,GAAgB,MAAM,CAAE,CAAxB;;AACA,SAAKC,OAAL,GAAe,MAAM,CAAE,CAAvB;;AACA,SAAKC,MAAL,GAAc,IAAIC,OAAJ,CAAY,CAACC,OAAD,EAAUC,MAAV,KAAqB;AAC7C,WAAKL,QAAL,GAAgBI,OAAhB;AACA,WAAKH,OAAL,GAAeI,MAAf;AACD,KAHa,CAAd;AAID;;AAMDC,EAAAA,WAAW,CAACC,IAAD,EAA0BC,OAA1B,EAA+D;AACxE,SAAKX,YAAL,CAAkBS,WAAlB,CAA8B;AAC5BG,MAAAA,MAAM,EAAE,YADoB;AAE5BF,MAAAA,IAF4B;AAG5BC,MAAAA;AAH4B,KAA9B;AAKD;;AAKDE,EAAAA,IAAI,CAACC,KAAD,EAAmB;AACrBlB,IAAAA,MAAM,CAAC,KAAKM,SAAN,CAAN;AACA,SAAKA,SAAL,GAAiB,KAAjB;;AACA,SAAKC,QAAL,CAAcW,KAAd;AACD;;AAKDC,EAAAA,KAAK,CAACA,KAAD,EAAqB;AACxBnB,IAAAA,MAAM,CAAC,KAAKM,SAAN,CAAN;AACA,SAAKA,SAAL,GAAiB,KAAjB;;AACA,SAAKE,OAAL,CAAaW,KAAb;AACD;;AAlD4B","sourcesContent":["import type {WorkerMessageType, WorkerMessagePayload} from '../../types';\nimport WorkerThread from './worker-thread';\nimport {assert} from '../env-utils/assert';\n\n/**\n * Represents one Job handled by a WorkerPool or WorkerFarm\n */\nexport default class WorkerJob {\n readonly name: string;\n readonly workerThread: WorkerThread;\n isRunning: boolean;\n /** Promise that resolves when Job is done */\n readonly result: Promise<any>;\n\n private _resolve: (value: any) => void;\n private _reject: (reason?: any) => void;\n\n constructor(jobName: string, workerThread: WorkerThread) {\n this.name = jobName;\n this.workerThread = workerThread;\n this.isRunning = true;\n this._resolve = () => {};\n this._reject = () => {};\n this.result = new Promise((resolve, reject) => {\n this._resolve = resolve;\n this._reject = reject;\n });\n }\n\n /**\n * Send a message to the job's worker thread\n * @param data any data structure, ideally consisting mostly of transferrable objects\n */\n postMessage(type: WorkerMessageType, payload: WorkerMessagePayload): void {\n this.workerThread.postMessage({\n source: 'loaders.gl', // Lets worker ignore unrelated messages\n type,\n payload\n });\n }\n\n /**\n * Call to resolve the `result` Promise with the supplied value\n */\n done(value: any): void {\n assert(this.isRunning);\n this.isRunning = false;\n this._resolve(value);\n }\n\n /**\n * Call to reject the `result` Promise with the supplied error\n */\n error(error: Error): void {\n assert(this.isRunning);\n this.isRunning = false;\n this._reject(error);\n }\n}\n"],"file":"worker-job.js"}
|
|
@@ -138,7 +138,7 @@ export default class WorkerPool {
|
|
|
138
138
|
|
|
139
139
|
if (this.count < this._getMaxConcurrency()) {
|
|
140
140
|
this.count++;
|
|
141
|
-
const name =
|
|
141
|
+
const name = "".concat(this.name.toLowerCase(), " (#").concat(this.count, " of ").concat(this.maxConcurrency, ")");
|
|
142
142
|
return new WorkerThread({
|
|
143
143
|
name,
|
|
144
144
|
source: this.source,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/worker-farm/worker-pool.ts"],"names":["isMobile","WorkerThread","WorkerJob","WorkerPool","constructor","props","source","url","setProps","destroy","idleQueue","forEach","worker","isDestroyed","name","undefined","maxConcurrency","maxMobileConcurrency","reuseWorkers","onDebug","startJob","onMessage","job","type","data","done","onError","error","startPromise","Promise","onStart","jobQueue","push","_startQueuedJob","length","workerThread","_getAvailableWorker","queuedJob","shift","message","backlog","payload","result","returnWorkerToQueue","shouldDestroyWorker","count","_getMaxConcurrency","toLowerCase"],"mappings":";AACA,SAAQA,QAAR,QAAuB,sBAAvB;AACA,OAAOC,YAAP,MAAyB,iBAAzB;AACA,OAAOC,SAAP,MAAsB,cAAtB;AAqCA,eAAe,MAAMC,UAAN,CAAiB;AAmB9BC,EAAAA,WAAW,CAACC,KAAD,EAAyB;AAAA,kCAlBrB,SAkBqB;;AAAA;;AAAA;;AAAA,4CAfX,CAeW;;AAAA,kDAdL,CAcK;;AAAA,qCAbW,MAAM,CAAE,CAanB;;AAAA,0CAZZ,IAYY;;AAAA,mCAVH,EAUG;;AAAA,sCATJ,EASI;;AAAA,uCARA,EAQA;;AAAA,mCAPpB,CAOoB;;AAAA,yCANd,KAMc;;AAClC,SAAKC,MAAL,GAAcD,KAAK,CAACC,MAApB;AACA,SAAKC,GAAL,GAAWF,KAAK,CAACE,GAAjB;AACA,SAAKC,QAAL,CAAcH,KAAd;AACD;;AAMDI,EAAAA,OAAO,GAAS;AAEd,SAAKC,SAAL,CAAeC,OAAf,CAAwBC,MAAD,IAAYA,MAAM,CAACH,OAAP,EAAnC;AACA,SAAKI,WAAL,GAAmB,IAAnB;AACD;;AAEDL,EAAAA,QAAQ,CAACH,KAAD,EAAyB;AAC/B,SAAKA,KAAL,GAAa,EAAC,GAAG,KAAKA,KAAT;AAAgB,SAAGA;AAAnB,KAAb;;AAEA,QAAIA,KAAK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AewB,MAAf,GAAwB,CAA5B,EAA+B;AAC7B,aAAO,KAAKxB,SAAL,CAAe4B,KAAf,MAA0B,IAAjC;AACD;;AAGD,QAAI,KAAKO,KAAL,GAAa,KAAKC,kBAAL,EAAjB,EAA4C;AAC1C,WAAKD,KAAL;AACA,YAAM/B,IAAI,GAAI,GAAE,KAAKA,IAAL,CAAUiC,WAAV,EAAwB,MAAK,KAAKF,KAAM,OAAM,KAAK7B,cAAe,GAAlF;AACA,aAAO,IAAIf,YAAJ,CAAiB;AAACa,QAAAA,IAAD;AAAOR,QAAAA,MAAM,EAAE,KAAKA,MAApB;AAA4BC,QAAAA,GAAG,EAAE,KAAKA;AAAtC,OAAjB,CAAP;AACD;;AAGD,WAAO,IAAP;AACD;;AAEDuC,EAAAA,kBAAkB,GAAG;AACnB,WAAO9C,QAAQ,GAAG,KAAKiB,oBAAR,GAA+B,KAAKD,cAAnD;AACD;;AAnK6B","sourcesContent":["import type {WorkerMessageType, WorkerMessagePayload} from '../../types';\nimport {isMobile} from '../env-utils/globals';\nimport WorkerThread from './worker-thread';\nimport WorkerJob from './worker-job';\n\n/** WorkerPool onDebug Callback Parameters */\ntype OnDebugParameters = {\n message: string;\n worker: string;\n name: string;\n job: string;\n backlog: number;\n workerThread: WorkerThread;\n};\n\n/** WorkerPool Properties */\nexport type WorkerPoolProps = {\n name?: string;\n source?: string; // | Function;\n url?: string;\n maxConcurrency?: number;\n maxMobileConcurrency?: number;\n onDebug?: (options: OnDebugParameters) => any;\n reuseWorkers?: boolean;\n};\n\n/** Private helper types */\ntype OnMessage = (job: WorkerJob, type: WorkerMessageType, payload: WorkerMessagePayload) => void;\ntype OnError = (job: WorkerJob, error: Error) => void;\n\ntype QueuedJob = {\n name: string;\n onMessage: OnMessage;\n onError: OnError;\n onStart: (value: any) => void; // Resolve job start promise\n};\n\n/**\n * Process multiple data messages with small pool of identical workers\n */\nexport default class WorkerPool {\n name: string = 'unnamed';\n source?: string; // | Function;\n url?: string;\n maxConcurrency: number = 1;\n maxMobileConcurrency: number = 1;\n onDebug: (options: OnDebugParameters) => any = () => {};\n reuseWorkers: boolean = true;\n\n private props: WorkerPoolProps = {};\n private jobQueue: QueuedJob[] = [];\n private idleQueue: WorkerThread[] = [];\n private count = 0;\n private isDestroyed = false;\n\n /**\n * @param processor - worker function\n * @param maxConcurrency - max count of workers\n */\n constructor(props: WorkerPoolProps) {\n this.source = props.source;\n this.url = props.url;\n this.setProps(props);\n }\n\n /**\n * Terminates all workers in the pool\n * @note Can free up significant memory\n */\n destroy(): void {\n // Destroy idle workers, active Workers will be destroyed on completion\n this.idleQueue.forEach((worker) => worker.destroy());\n this.isDestroyed = true;\n }\n\n setProps(props: WorkerPoolProps) {\n this.props = {...this.props, ...props};\n\n if (props.name !== undefined) {\n this.name = props.name;\n }\n if (props.maxConcurrency !== undefined) {\n this.maxConcurrency = props.maxConcurrency;\n }\n if (props.maxMobileConcurrency !== undefined) {\n this.maxMobileConcurrency = props.maxMobileConcurrency;\n }\n if (props.reuseWorkers !== undefined) {\n this.reuseWorkers = props.reuseWorkers;\n }\n if (props.onDebug !== undefined) {\n this.onDebug = props.onDebug;\n }\n }\n\n async startJob(\n name: string,\n onMessage: OnMessage = (job, type, data) => job.done(data),\n onError: OnError = (job, error) => job.error(error)\n ): Promise<WorkerJob> {\n // Promise resolves when thread starts working on this job\n const startPromise = new Promise<WorkerJob>((onStart) => {\n // Promise resolves when thread completes or fails working on this job\n this.jobQueue.push({name, onMessage, onError, onStart});\n return this;\n });\n this._startQueuedJob(); // eslint-disable-line @typescript-eslint/no-floating-promises\n return await startPromise;\n }\n\n // PRIVATE\n\n /**\n * Starts first queued job if worker is available or can be created\n * Called when job is started and whenever a worker returns to the idleQueue\n */\n async _startQueuedJob(): Promise<void> {\n if (!this.jobQueue.length) {\n return;\n }\n\n const workerThread = this._getAvailableWorker();\n if (!workerThread) {\n return;\n }\n\n // We have a worker, dequeue and start the job\n const queuedJob = this.jobQueue.shift();\n if (queuedJob) {\n // Emit a debug event\n // @ts-ignore\n this.onDebug({\n message: 'Starting job',\n name: queuedJob.name,\n workerThread,\n backlog: this.jobQueue.length\n });\n\n // Create a worker job to let the app access thread and manage job completion\n const job = new WorkerJob(queuedJob.name, workerThread);\n\n // Set the worker thread's message handlers\n workerThread.onMessage = (data) => queuedJob.onMessage(job, data.type, data.payload);\n workerThread.onError = (error) => queuedJob.onError(job, error);\n\n // Resolve the start promise so that the app can start sending messages to worker\n queuedJob.onStart(job);\n\n // Wait for the app to signal that the job is complete, then return worker to queue\n try {\n await job.result;\n } finally {\n this.returnWorkerToQueue(workerThread);\n }\n }\n }\n\n /**\n * Returns a worker to the idle queue\n * Destroys the worker if\n * - pool is destroyed\n * - if this pool doesn't reuse workers\n * - if maxConcurrency has been lowered\n * @param worker\n */\n returnWorkerToQueue(worker: WorkerThread) {\n const shouldDestroyWorker =\n this.isDestroyed || !this.reuseWorkers || this.count > this._getMaxConcurrency();\n\n if (shouldDestroyWorker) {\n worker.destroy();\n this.count--;\n } else {\n this.idleQueue.push(worker);\n }\n\n if (!this.isDestroyed) {\n this._startQueuedJob(); // eslint-disable-line @typescript-eslint/no-floating-promises\n }\n }\n\n /**\n * Returns idle worker or creates new worker if maxConcurrency has not been reached\n */\n _getAvailableWorker(): WorkerThread | null {\n // If a worker has completed and returned to the queue, it can be used\n if (this.idleQueue.length > 0) {\n return this.idleQueue.shift() || null;\n }\n\n // Create fresh worker if we haven't yet created the max amount of worker threads for this worker source\n if (this.count < this._getMaxConcurrency()) {\n this.count++;\n const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;\n return new WorkerThread({name, source: this.source, url: this.url});\n }\n\n // No worker available, have to wait\n return null;\n }\n\n _getMaxConcurrency() {\n return isMobile ? this.maxMobileConcurrency : this.maxConcurrency;\n }\n}\n"],"file":"worker-pool.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/worker-farm/worker-pool.ts"],"names":["isMobile","WorkerThread","WorkerJob","WorkerPool","constructor","props","source","url","setProps","destroy","idleQueue","forEach","worker","isDestroyed","name","undefined","maxConcurrency","maxMobileConcurrency","reuseWorkers","onDebug","startJob","onMessage","job","type","data","done","onError","error","startPromise","Promise","onStart","jobQueue","push","_startQueuedJob","length","workerThread","_getAvailableWorker","queuedJob","shift","message","backlog","payload","result","returnWorkerToQueue","shouldDestroyWorker","count","_getMaxConcurrency","toLowerCase"],"mappings":";AACA,SAAQA,QAAR,QAAuB,sBAAvB;AACA,OAAOC,YAAP,MAAyB,iBAAzB;AACA,OAAOC,SAAP,MAAsB,cAAtB;AAqCA,eAAe,MAAMC,UAAN,CAAiB;AAmB9BC,EAAAA,WAAW,CAACC,KAAD,EAAyB;AAAA,kCAlBrB,SAkBqB;;AAAA;;AAAA;;AAAA,4CAfX,CAeW;;AAAA,kDAdL,CAcK;;AAAA,qCAbW,MAAM,CAAE,CAanB;;AAAA,0CAZZ,IAYY;;AAAA,mCAVH,EAUG;;AAAA,sCATJ,EASI;;AAAA,uCARA,EAQA;;AAAA,mCAPpB,CAOoB;;AAAA,yCANd,KAMc;;AAClC,SAAKC,MAAL,GAAcD,KAAK,CAACC,MAApB;AACA,SAAKC,GAAL,GAAWF,KAAK,CAACE,GAAjB;AACA,SAAKC,QAAL,CAAcH,KAAd;AACD;;AAMDI,EAAAA,OAAO,GAAS;AAEd,SAAKC,SAAL,CAAeC,OAAf,CAAwBC,MAAD,IAAYA,MAAM,CAACH,OAAP,EAAnC;AACA,SAAKI,WAAL,GAAmB,IAAnB;AACD;;AAEDL,EAAAA,QAAQ,CAACH,KAAD,EAAyB;AAC/B,SAAKA,KAAL,GAAa,EAAC,GAAG,KAAKA,KAAT;AAAgB,SAAGA;AAAnB,KAAb;;AAEA,QAAIA,KAAK,CAACS,IAAN,KAAeC,SAAnB,EAA8B;AAC5B,WAAKD,IAAL,GAAYT,KAAK,CAACS,IAAlB;AACD;;AACD,QAAIT,KAAK,CAACW,cAAN,KAAyBD,SAA7B,EAAwC;AACtC,WAAKC,cA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AC1C,WAAKD,KAAL;AACA,YAAM/B,IAAI,aAAM,KAAKA,IAAL,CAAUiC,WAAV,EAAN,gBAAmC,KAAKF,KAAxC,iBAAoD,KAAK7B,cAAzD,MAAV;AACA,aAAO,IAAIf,YAAJ,CAAiB;AAACa,QAAAA,IAAD;AAAOR,QAAAA,MAAM,EAAE,KAAKA,MAApB;AAA4BC,QAAAA,GAAG,EAAE,KAAKA;AAAtC,OAAjB,CAAP;AACD;;AAGD,WAAO,IAAP;AACD;;AAEDuC,EAAAA,kBAAkB,GAAG;AACnB,WAAO9C,QAAQ,GAAG,KAAKiB,oBAAR,GAA+B,KAAKD,cAAnD;AACD;;AAnK6B","sourcesContent":["import type {WorkerMessageType, WorkerMessagePayload} from '../../types';\nimport {isMobile} from '../env-utils/globals';\nimport WorkerThread from './worker-thread';\nimport WorkerJob from './worker-job';\n\n/** WorkerPool onDebug Callback Parameters */\ntype OnDebugParameters = {\n message: string;\n worker: string;\n name: string;\n job: string;\n backlog: number;\n workerThread: WorkerThread;\n};\n\n/** WorkerPool Properties */\nexport type WorkerPoolProps = {\n name?: string;\n source?: string; // | Function;\n url?: string;\n maxConcurrency?: number;\n maxMobileConcurrency?: number;\n onDebug?: (options: OnDebugParameters) => any;\n reuseWorkers?: boolean;\n};\n\n/** Private helper types */\ntype OnMessage = (job: WorkerJob, type: WorkerMessageType, payload: WorkerMessagePayload) => void;\ntype OnError = (job: WorkerJob, error: Error) => void;\n\ntype QueuedJob = {\n name: string;\n onMessage: OnMessage;\n onError: OnError;\n onStart: (value: any) => void; // Resolve job start promise\n};\n\n/**\n * Process multiple data messages with small pool of identical workers\n */\nexport default class WorkerPool {\n name: string = 'unnamed';\n source?: string; // | Function;\n url?: string;\n maxConcurrency: number = 1;\n maxMobileConcurrency: number = 1;\n onDebug: (options: OnDebugParameters) => any = () => {};\n reuseWorkers: boolean = true;\n\n private props: WorkerPoolProps = {};\n private jobQueue: QueuedJob[] = [];\n private idleQueue: WorkerThread[] = [];\n private count = 0;\n private isDestroyed = false;\n\n /**\n * @param processor - worker function\n * @param maxConcurrency - max count of workers\n */\n constructor(props: WorkerPoolProps) {\n this.source = props.source;\n this.url = props.url;\n this.setProps(props);\n }\n\n /**\n * Terminates all workers in the pool\n * @note Can free up significant memory\n */\n destroy(): void {\n // Destroy idle workers, active Workers will be destroyed on completion\n this.idleQueue.forEach((worker) => worker.destroy());\n this.isDestroyed = true;\n }\n\n setProps(props: WorkerPoolProps) {\n this.props = {...this.props, ...props};\n\n if (props.name !== undefined) {\n this.name = props.name;\n }\n if (props.maxConcurrency !== undefined) {\n this.maxConcurrency = props.maxConcurrency;\n }\n if (props.maxMobileConcurrency !== undefined) {\n this.maxMobileConcurrency = props.maxMobileConcurrency;\n }\n if (props.reuseWorkers !== undefined) {\n this.reuseWorkers = props.reuseWorkers;\n }\n if (props.onDebug !== undefined) {\n this.onDebug = props.onDebug;\n }\n }\n\n async startJob(\n name: string,\n onMessage: OnMessage = (job, type, data) => job.done(data),\n onError: OnError = (job, error) => job.error(error)\n ): Promise<WorkerJob> {\n // Promise resolves when thread starts working on this job\n const startPromise = new Promise<WorkerJob>((onStart) => {\n // Promise resolves when thread completes or fails working on this job\n this.jobQueue.push({name, onMessage, onError, onStart});\n return this;\n });\n this._startQueuedJob(); // eslint-disable-line @typescript-eslint/no-floating-promises\n return await startPromise;\n }\n\n // PRIVATE\n\n /**\n * Starts first queued job if worker is available or can be created\n * Called when job is started and whenever a worker returns to the idleQueue\n */\n async _startQueuedJob(): Promise<void> {\n if (!this.jobQueue.length) {\n return;\n }\n\n const workerThread = this._getAvailableWorker();\n if (!workerThread) {\n return;\n }\n\n // We have a worker, dequeue and start the job\n const queuedJob = this.jobQueue.shift();\n if (queuedJob) {\n // Emit a debug event\n // @ts-ignore\n this.onDebug({\n message: 'Starting job',\n name: queuedJob.name,\n workerThread,\n backlog: this.jobQueue.length\n });\n\n // Create a worker job to let the app access thread and manage job completion\n const job = new WorkerJob(queuedJob.name, workerThread);\n\n // Set the worker thread's message handlers\n workerThread.onMessage = (data) => queuedJob.onMessage(job, data.type, data.payload);\n workerThread.onError = (error) => queuedJob.onError(job, error);\n\n // Resolve the start promise so that the app can start sending messages to worker\n queuedJob.onStart(job);\n\n // Wait for the app to signal that the job is complete, then return worker to queue\n try {\n await job.result;\n } finally {\n this.returnWorkerToQueue(workerThread);\n }\n }\n }\n\n /**\n * Returns a worker to the idle queue\n * Destroys the worker if\n * - pool is destroyed\n * - if this pool doesn't reuse workers\n * - if maxConcurrency has been lowered\n * @param worker\n */\n returnWorkerToQueue(worker: WorkerThread) {\n const shouldDestroyWorker =\n this.isDestroyed || !this.reuseWorkers || this.count > this._getMaxConcurrency();\n\n if (shouldDestroyWorker) {\n worker.destroy();\n this.count--;\n } else {\n this.idleQueue.push(worker);\n }\n\n if (!this.isDestroyed) {\n this._startQueuedJob(); // eslint-disable-line @typescript-eslint/no-floating-promises\n }\n }\n\n /**\n * Returns idle worker or creates new worker if maxConcurrency has not been reached\n */\n _getAvailableWorker(): WorkerThread | null {\n // If a worker has completed and returned to the queue, it can be used\n if (this.idleQueue.length > 0) {\n return this.idleQueue.shift() || null;\n }\n\n // Create fresh worker if we haven't yet created the max amount of worker threads for this worker source\n if (this.count < this._getMaxConcurrency()) {\n this.count++;\n const name = `${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;\n return new WorkerThread({name, source: this.source, url: this.url});\n }\n\n // No worker available, have to wait\n return null;\n }\n\n _getMaxConcurrency() {\n return isMobile ? this.maxMobileConcurrency : this.maxConcurrency;\n }\n}\n"],"file":"worker-pool.js"}
|
|
@@ -61,14 +61,14 @@ export default class WorkerThread {
|
|
|
61
61
|
|
|
62
62
|
_getErrorFromErrorEvent(event) {
|
|
63
63
|
let message = 'Failed to load ';
|
|
64
|
-
message +=
|
|
64
|
+
message += "worker ".concat(this.name, " from ").concat(this.url, ". ");
|
|
65
65
|
|
|
66
66
|
if (event.message) {
|
|
67
|
-
message +=
|
|
67
|
+
message += "".concat(event.message, " in ");
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
if (event.lineno) {
|
|
71
|
-
message +=
|
|
71
|
+
message += ":".concat(event.lineno, ":").concat(event.colno);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
return new Error(message);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/worker-farm/worker-thread.ts"],"names":["assert","getLoadableWorkerURL","getTransferList","NOOP","WorkerThread","isSupported","Worker","constructor","props","name","source","url","onMessage","onError","error","console","log","worker","_createBrowserWorker","destroy","terminate","terminated","isRunning","Boolean","postMessage","data","transferList","_getErrorFromErrorEvent","event","message","lineno","colno","Error","_loadableURL","onmessage","onerror","onmessageerror"],"mappings":";AAAA,SAAQA,MAAR,QAAqB,qBAArB;AACA,SAAQC,oBAAR,QAAmC,yCAAnC;AACA,SAAQC,eAAR,QAA8B,mCAA9B;;AAEA,MAAMC,IAAI,GAAG,MAAM,CAAE,CAArB;;AAWA,eAAe,MAAMC,YAAN,CAAmB;AAWd,SAAXC,WAAW,GAAY;AAC5B,WAAO,OAAOC,MAAP,KAAkB,WAAzB;AACD;;AAEDC,EAAAA,WAAW,CAACC,KAAD,EAA2B;AAAA;;AAAA;;AAAA;;AAAA,wCAXhB,KAWgB;;AAAA;;AAAA;;AAAA;;AAAA,0CANP,EAMO;;AACpC,UAAM;AAACC,MAAAA,IAAD;AAAOC,MAAAA,MAAP;AAAeC,MAAAA;AAAf,QAAsBH,KAA5B;AACAR,IAAAA,MAAM,CAACU,MAAM,IAAIC,GAAX,CAAN;AACA,SAAKF,IAAL,GAAYA,IAAZ;AACA,SAAKC,MAAL,GAAcA,MAAd;AACA,SAAKC,GAAL,GAAWA,GAAX;AACA,SAAKC,SAAL,GAAiBT,IAAjB;;AACA,SAAKU,OAAL,GAAgBC,KAAD,IAAWC,OAAO,CAACC,GAAR,CAAYF,KAAZ,CAA1B;;AAEA,SAAKG,MAAL,GAAc,KAAKC,oBAAL,EAAd;AACD;;AAMDC,EAAAA,OAAO,GAAS;AACd,SAAKP,SAAL,GAAiBT,IAAjB;AACA,SAAKU,OAAL,GAAeV,IAAf;AAEA,SAAKc,MAAL,CAAYG,SAAZ;AACA,SAAKC,UAAL,GAAkB,IAAlB;AACD;;AAEY,MAATC,SAAS,GAAG;AACd,WAAOC,OAAO,CAAC,KAAKX,SAAN,CAAd;AACD;;AAODY,EAAAA,WAAW,CAACC,IAAD,EAAYC,YAAZ,EAAwC;AACjDA,IAAAA,YAAY,GAAGA,YAAY,IAAIxB,eAAe,CAACuB,IAAD,CAA9C;AAEA,SAAKR,MAAL,CAAYO,WAAZ,CAAwBC,IAAxB,EAA8BC,YAA9B;AACD;;AAQDC,EAAAA,uBAAuB,CAACC,KAAD,
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/worker-farm/worker-thread.ts"],"names":["assert","getLoadableWorkerURL","getTransferList","NOOP","WorkerThread","isSupported","Worker","constructor","props","name","source","url","onMessage","onError","error","console","log","worker","_createBrowserWorker","destroy","terminate","terminated","isRunning","Boolean","postMessage","data","transferList","_getErrorFromErrorEvent","event","message","lineno","colno","Error","_loadableURL","onmessage","onerror","onmessageerror"],"mappings":";AAAA,SAAQA,MAAR,QAAqB,qBAArB;AACA,SAAQC,oBAAR,QAAmC,yCAAnC;AACA,SAAQC,eAAR,QAA8B,mCAA9B;;AAEA,MAAMC,IAAI,GAAG,MAAM,CAAE,CAArB;;AAWA,eAAe,MAAMC,YAAN,CAAmB;AAWd,SAAXC,WAAW,GAAY;AAC5B,WAAO,OAAOC,MAAP,KAAkB,WAAzB;AACD;;AAEDC,EAAAA,WAAW,CAACC,KAAD,EAA2B;AAAA;;AAAA;;AAAA;;AAAA,wCAXhB,KAWgB;;AAAA;;AAAA;;AAAA;;AAAA,0CANP,EAMO;;AACpC,UAAM;AAACC,MAAAA,IAAD;AAAOC,MAAAA,MAAP;AAAeC,MAAAA;AAAf,QAAsBH,KAA5B;AACAR,IAAAA,MAAM,CAACU,MAAM,IA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Ad;AAAsBC,MAAAA,GAAG,EAAE,KAAKA;AAAhC,KAAD,CAAxC;AACA,UAAMM,MAAM,GAAG,IAAIX,MAAJ,CAAW,KAAK2B,YAAhB,EAA8B;AAACxB,MAAAA,IAAI,EAAE,KAAKA;AAAZ,KAA9B,CAAf;;AAEAQ,IAAAA,MAAM,CAACiB,SAAP,GAAoBN,KAAD,IAAW;AAC5B,UAAI,CAACA,KAAK,CAACH,IAAX,EAAiB;AACf,aAAKZ,OAAL,CAAa,IAAImB,KAAJ,CAAU,kBAAV,CAAb;AACD,OAFD,MAEO;AACL,aAAKpB,SAAL,CAAegB,KAAK,CAACH,IAArB;AACD;AACF,KAND;;AAQAR,IAAAA,MAAM,CAACkB,OAAP,GAAkBrB,KAAD,IAA6B;AAC5C,WAAKD,OAAL,CAAa,KAAKc,uBAAL,CAA6Bb,KAA7B,CAAb;AACA,WAAKO,UAAL,GAAkB,IAAlB;AACD,KAHD;;AAKAJ,IAAAA,MAAM,CAACmB,cAAP,GAAyBR,KAAD,IAAWb,OAAO,CAACD,KAAR,CAAcc,KAAd,CAAnC;;AAEA,WAAOX,MAAP;AACD;;AApG+B","sourcesContent":["import {assert} from '../env-utils/assert';\nimport {getLoadableWorkerURL} from '../worker-utils/get-loadable-worker-url';\nimport {getTransferList} from '../worker-utils/get-transfer-list';\n\nconst NOOP = () => {};\n\nexport type WorkerThreadProps = {\n name: string;\n source?: string;\n url?: string;\n};\n\n/**\n * Represents one worker thread\n */\nexport default class WorkerThread {\n readonly name: string;\n readonly source: string | undefined;\n readonly url: string | undefined;\n terminated: boolean = false;\n worker: Worker;\n onMessage: (message: any) => void;\n onError: (error: Error) => void;\n\n private _loadableURL: string = '';\n\n static isSupported(): boolean {\n return typeof Worker !== 'undefined';\n }\n\n constructor(props: WorkerThreadProps) {\n const {name, source, url} = props;\n assert(source || url); // Either source or url must be defined\n this.name = name;\n this.source = source;\n this.url = url;\n this.onMessage = NOOP;\n this.onError = (error) => console.log(error); // eslint-disable-line\n\n this.worker = this._createBrowserWorker();\n }\n\n /**\n * Terminate this worker thread\n * @note Can free up significant memory\n */\n destroy(): void {\n this.onMessage = NOOP;\n this.onError = NOOP;\n // @ts-ignore\n this.worker.terminate();\n this.terminated = true;\n }\n\n get isRunning() {\n return Boolean(this.onMessage);\n }\n\n /**\n * Send a message to this worker thread\n * @param data any data structure, ideally consisting mostly of transferrable objects\n * @param transferList If not supplied, calculated automatically by traversing data\n */\n postMessage(data: any, transferList?: any[]): void {\n transferList = transferList || getTransferList(data);\n // @ts-ignore\n this.worker.postMessage(data, transferList);\n }\n\n // PRIVATE\n\n /**\n * Generate a standard Error from an ErrorEvent\n * @param {ErrorEvent} event\n */\n _getErrorFromErrorEvent(event: ErrorEvent): Error {\n // Note Error object does not have the expected fields if loading failed completely\n // https://developer.mozilla.org/en-US/docs/Web/API/Worker#Event_handlers\n // https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent\n let message = 'Failed to load ';\n message += `worker ${this.name} from ${this.url}. `;\n if (event.message) {\n message += `${event.message} in `;\n }\n // const hasFilename = event.filename && !event.filename.startsWith('blob:');\n // message += hasFilename ? event.filename : this.source.slice(0, 100);\n if (event.lineno) {\n message += `:${event.lineno}:${event.colno}`;\n }\n return new Error(message);\n }\n\n /**\n * Creates a worker thread on the browser\n */\n _createBrowserWorker() {\n this._loadableURL = getLoadableWorkerURL({source: this.source, url: this.url});\n const worker = new Worker(this._loadableURL, {name: this.name});\n\n worker.onmessage = (event) => {\n if (!event.data) {\n this.onError(new Error('No data received'));\n } else {\n this.onMessage(event.data);\n }\n };\n // This callback represents an uncaught exception in the worker thread\n worker.onerror = (error: ErrorEvent): void => {\n this.onError(this._getErrorFromErrorEvent(error));\n this.terminated = true;\n };\n // TODO - not clear when this would be called, for now just log in case it happens\n worker.onmessageerror = (event) => console.error(event); // eslint-disable-line\n\n return worker;\n }\n}\n"],"file":"worker-thread.js"}
|
|
@@ -37,12 +37,6 @@ function getLoadableWorkerURLFromSource(workerSource) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
function buildScriptSource(workerUrl) {
|
|
40
|
-
return
|
|
41
|
-
try {
|
|
42
|
-
importScripts('${workerUrl}');
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.error(error);
|
|
45
|
-
throw error;
|
|
46
|
-
}`;
|
|
40
|
+
return "try {\n importScripts('".concat(workerUrl, "');\n} catch (error) {\n console.error(error);\n throw error;\n}");
|
|
47
41
|
}
|
|
48
42
|
//# sourceMappingURL=get-loadable-worker-url.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/lib/worker-utils/get-loadable-worker-url.ts"],"names":["assert","workerURLCache","Map","getLoadableWorkerURL","props","source","url","workerURL","get","getLoadableWorkerURLFromURL","set","getLoadableWorkerURLFromSource","startsWith","workerSource","buildScriptSource","blob","Blob","type","URL","createObjectURL","workerUrl"],"mappings":"AAAA,SAAQA,MAAR,QAAqB,qBAArB;AAEA,MAAMC,cAAc,GAAG,IAAIC,GAAJ,EAAvB;AAWA,OAAO,SAASC,oBAAT,CAA8BC,KAA9B,EAAsE;AAC3EJ,EAAAA,MAAM,CAAEI,KAAK,CAACC,MAAN,IAAgB,CAACD,KAAK,CAACE,GAAxB,IAAiC,CAACF,KAAK,CAACC,MAAP,IAAiBD,KAAK,CAACE,GAAzD,CAAN;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;;AAEDP,EAAAA,MAAM,CAACO,SAAD,CAAN;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,QAAMO,YAAY,GAAGC,iBAAiB,CAACR,GAAD,CAAtC;AACA,SAAOK,8BAA8B,CAACE,YAAD,CAArC;AACD;;AAOD,SAASF,8BAAT,CAAwCE,YAAxC,EAAsE;AAGpE,QAAME,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,
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/worker-utils/get-loadable-worker-url.ts"],"names":["assert","workerURLCache","Map","getLoadableWorkerURL","props","source","url","workerURL","get","getLoadableWorkerURLFromURL","set","getLoadableWorkerURLFromSource","startsWith","workerSource","buildScriptSource","blob","Blob","type","URL","createObjectURL","workerUrl"],"mappings":"AAAA,SAAQA,MAAR,QAAqB,qBAArB;AAEA,MAAMC,cAAc,GAAG,IAAIC,GAAJ,EAAvB;AAWA,OAAO,SAASC,oBAAT,CAA8BC,KAA9B,EAAsE;AAC3EJ,EAAAA,MAAM,CAAEI,KAAK,CAACC,MAAN,IAAgB,CAACD,KAAK,CAACE,GAAxB,IAAiC,CAACF,KAAK,CAACC,MAAP,IAAiBD,KAAK,CAACE,GAAzD,CAAN;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;;AAEDP,EAAAA,MAAM,CAACO,SAAD,CAAN;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,QAAMO,YAAY,GAAGC,iBAAiB,CAACR,GAAD,CAAtC;AACA,SAAOK,8BAA8B,CAACE,YAAD,CAArC;AACD;;AAOD,SAASF,8BAAT,CAAwCE,YAAxC,EAAsE;AAGpE,QAAME,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 +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":"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,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,
|
|
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":"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,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","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"],"file":"get-transfer-list.js"}
|
|
@@ -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":"AAIA,OAAO,SAASA,4BAAT,CAAsCC,MAAtC,EAA8D;AAInE,SAAOC,IAAI,CAACC,KAAL,CAAWC,aAAa,CAACH,MAAD,CAAxB,CAAP;AACD;;AAED,SAASG,aAAT,CAAuBC,CAAvB,
|
|
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":"AAIA,OAAO,SAASA,4BAAT,CAAsCC,MAAtC,EAA8D;AAInE,SAAOC,IAAI,CAACC,KAAL,CAAWC,aAAa,CAACH,MAAD,CAAxB,CAAP;AACD;;AAED,SAASG,aAAT,CAAuBC,CAAvB,EAAmC;AACjC,QAAMC,KAAK,GAAG,IAAIC,GAAJ,EAAd;AACA,SAAOL,IAAI,CAACM,SAAL,CAAeH,CAAf,EAAkB,CAACI,GAAD,EAAMC,KAAN,KAAgB;AACvC,QAAI,OAAOA,KAAP,KAAiB,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: unknown) {\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"}
|
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
|
-
!*** /home/user/apps/loaders.
|
|
92
|
-
|
|
90
|
+
/*!**************************************************************************************************!*\
|
|
91
|
+
!*** /home/user/apps/loaders.gl_duplicate/node_modules/@babel/runtime/helpers/defineProperty.js ***!
|
|
92
|
+
\**************************************************************************************************/
|
|
93
93
|
/*! no static exports found */
|
|
94
94
|
/***/ (function(module, exports) {
|
|
95
95
|
|
|
@@ -313,7 +313,7 @@ function createWorker(process, processInBatches) {
|
|
|
313
313
|
|
|
314
314
|
inputBatches = new _async_queue_async_queue__WEBPACK_IMPORTED_MODULE_0__["default"]();
|
|
315
315
|
options = payload.options || {};
|
|
316
|
-
const resultIterator = processInBatches(inputBatches, options, context
|
|
316
|
+
const resultIterator = processInBatches(inputBatches, options, context);
|
|
317
317
|
|
|
318
318
|
for await (const batch of resultIterator) {
|
|
319
319
|
_worker_farm_worker_body__WEBPACK_IMPORTED_MODULE_1__["default"].postMessage('output-batch', {
|
package/dist/null-worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,EAAkB;AAChB,YAAM,IAAII,KAAJ,CAAU,QAAV,CAAN;AAC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AR,CAAlB,EAAmC;AACxC;AACAJ,gBAAY,CAACG,GAAb,CAAiBN,MAAM,CAACO,MAAxB;AACD,GAHM,MAGA,IAAIC,WAAW,CAACC,MAAZ,CAAmBT,MAAnB,CAAJ,EAAgC,CACrC;AACA;AACD,GAHM,MAGA,IAAIC,SAAS,IAAI,OAAOD,MAAP,KAAkB,QAAnC,EAA6C;AAClD,SAAK,MAAMU,GAAX,IAAkBV,MAAlB,EAA0B;AACxB;AACAF,qBAAe,CAACE,MAAM,CAACU,GAAD,CAAP,EAAcT,SAAd,EAAyBE,YAAzB,CAAf;AACD;AACF,GAnBe,CAqBhB;AACA;;;AACA,SAAOD,SAAS,KAAKvC,SAAd,GAA0BgD,KAAK,CAACC,IAAN,CAAWT,YAAX,CAA1B,GAAqD,EAA5D;AACD,C,CAED;;AACA,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,OAAOK,WAAP,KAAuB,WAAvB,IAAsCb,MAAM,YAAYa,WAA5D,EAAyE;AACvE,WAAO,IAAP;AACD;;AACD,MAAI,OAAOC,WAAP,KAAuB,WAAvB,IAAsCd,MAAM,YAAYc,WAA5D,EAAyE;AACvE,WAAO,IAAP;AACD,GAZ6B,CAa9B;;;AACA,MAAI,OAAOC,eAAP,KAA2B,WAA3B,IAA0Cf,MAAM,YAAYe,eAAhE,EAAiF;AAC/E,WAAO,IAAP;AACD;;AACD,SAAO,KAAP;AACD,C;;;;;;;;;;;;AC5DD;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_duplicate/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;;;Q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OD,MAAP,KAAkB,QAAnC,EAA6C;AAClD,SAAK,MAAMU,GAAX,IAAkBV,MAAlB,EAA0B;AACxB;AACAF,qBAAe,CAACE,MAAM,CAACU,GAAD,CAAP,EAAcT,SAAd,EAAyBE,YAAzB,CAAf;AACD;AACF,GAnBe,CAqBhB;AACA;;;AACA,SAAOD,SAAS,KAAKvC,SAAd,GAA0BgD,KAAK,CAACC,IAAN,CAAWT,YAAX,CAA1B,GAAqD,EAA5D;AACD,C,CAED;;AACA,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,OAAOK,WAAP,KAAuB,WAAvB,IAAsCb,MAAM,YAAYa,WAA5D,EAAyE;AACvE,WAAO,IAAP;AACD;;AACD,MAAI,OAAOC,WAAP,KAAuB,WAAvB,IAAsCd,MAAM,YAAYc,WAA5D,EAAyE;AACvE,WAAO,IAAP;AACD,GAZsC,CAavC;;;AACA,MAAI,OAAOC,eAAP,KAA2B,WAA3B,IAA0Cf,MAAM,YAAYe,eAAhE,EAAiF;AAC/E,WAAO,IAAP;AACD;;AACD,SAAO,KAAP;AACD,C;;;;;;;;;;;;AC5DD;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: 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 // 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<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 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: MessageEvent<any>) => {\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: 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","// 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","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
|
+
"version": "4.0.0-alpha.3",
|
|
4
4
|
"description": "Utilities for running tasks on worker threads",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"browser": {
|
|
28
28
|
"child_process": false,
|
|
29
29
|
"fs": false,
|
|
30
|
-
"./src/lib/node/require-utils.node.
|
|
30
|
+
"./src/lib/node/require-utils.node.ts": false,
|
|
31
31
|
"./dist/es5/lib/node/require-utils.node.js": false,
|
|
32
32
|
"./dist/esm/lib/node/require-utils.node.js": false,
|
|
33
33
|
"./src/lib/process-utils/child-process-proxy.ts": false,
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"scripts": {
|
|
38
38
|
"pre-build": "npm run build-workers",
|
|
39
39
|
"pre-build-disabled": "npm run build-bundle && npm run build-workers",
|
|
40
|
-
"build-bundle": "
|
|
40
|
+
"build-bundle": "esbuild src/bundle.ts --outfile=dist/bundle.js",
|
|
41
41
|
"build-workers": "webpack --entry ./src/workers/null-worker.ts --output ./dist/null-worker.js --env.dev --config ../../scripts/webpack/worker.js"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@babel/runtime": "^7.3.1"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "ded84630d02ba4fc97277ebecea3e42ae1bc2616"
|
|
47
47
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
// Change to `latest` on production branches
|
|
5
5
|
const DEFAULT_VERSION = 'beta';
|
|
6
|
-
declare let __VERSION__;
|
|
6
|
+
declare let __VERSION__: string;
|
|
7
7
|
export const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : DEFAULT_VERSION;
|
|
8
8
|
if (typeof __VERSION__ === 'undefined') {
|
|
9
9
|
// eslint-disable-next-line
|
|
@@ -8,7 +8,7 @@ import {VERSION as __VERSION__} from '../env-utils/version';
|
|
|
8
8
|
const LATEST = 'beta';
|
|
9
9
|
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : LATEST;
|
|
10
10
|
|
|
11
|
-
const loadLibraryPromises = {}; // promises
|
|
11
|
+
const loadLibraryPromises: Record<string, Promise<any>> = {}; // promises
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Dynamically loads a library ("module")
|
|
@@ -35,13 +35,15 @@ export async function loadLibrary(
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
// Ensure libraries are only loaded once
|
|
38
|
+
|
|
38
39
|
loadLibraryPromises[libraryUrl] =
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
39
41
|
loadLibraryPromises[libraryUrl] || loadLibraryFromFile(libraryUrl);
|
|
40
42
|
return await loadLibraryPromises[libraryUrl];
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
// TODO - sort out how to resolve paths for main/worker and dev/prod
|
|
44
|
-
export function getLibraryUrl(library, moduleName?: string, options
|
|
46
|
+
export function getLibraryUrl(library: string, moduleName?: string, options?: any): string {
|
|
45
47
|
// Check if already a URL
|
|
46
48
|
if (library.startsWith('http')) {
|
|
47
49
|
return library;
|
|
@@ -73,7 +75,7 @@ export function getLibraryUrl(library, moduleName?: string, options?): string {
|
|
|
73
75
|
return `modules/${moduleName}/src/libs/${library}`;
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
async function loadLibraryFromFile(libraryUrl) {
|
|
78
|
+
async function loadLibraryFromFile(libraryUrl: string): Promise<any> {
|
|
77
79
|
if (libraryUrl.endsWith('wasm')) {
|
|
78
80
|
const response = await fetch(libraryUrl);
|
|
79
81
|
return await response.arrayBuffer();
|
|
@@ -113,7 +115,7 @@ async function loadScriptFromFile(libraryUrl) {
|
|
|
113
115
|
// - Potentially bypasses CORS
|
|
114
116
|
// Upside is that this separates fetching and parsing
|
|
115
117
|
// we could create a`LibraryLoader` or`ModuleLoader`
|
|
116
|
-
function loadLibraryFromString(scriptSource, id) {
|
|
118
|
+
function loadLibraryFromString(scriptSource: string, id: string): null | any {
|
|
117
119
|
if (!isBrowser) {
|
|
118
120
|
return node.requireFromString && node.requireFromString(scriptSource, id);
|
|
119
121
|
}
|
|
@@ -11,7 +11,7 @@ import path from 'path';
|
|
|
11
11
|
// Relative names are resolved relative to cwd
|
|
12
12
|
// This indirect function is provided because webpack will try to bundle `module.require`.
|
|
13
13
|
// this file is not visible to webpack (it is excluded in the package.json "browser" field).
|
|
14
|
-
export async function requireFromFile(filename) {
|
|
14
|
+
export async function requireFromFile(filename: string): Promise<any> {
|
|
15
15
|
if (filename.startsWith('http')) {
|
|
16
16
|
const response = await fetch(filename);
|
|
17
17
|
const code = await response.text();
|
|
@@ -30,18 +30,19 @@ export async function requireFromFile(filename) {
|
|
|
30
30
|
// - `options.appendPaths` Type: Array List of paths, that will be appended to module paths.
|
|
31
31
|
// Useful, when you want to be able require modules from these paths.
|
|
32
32
|
// - `options.prependPaths` Type: Array Same as appendPaths, but paths will be prepended.
|
|
33
|
-
export function requireFromString(
|
|
33
|
+
export function requireFromString(
|
|
34
|
+
code: string,
|
|
35
|
+
filename = '',
|
|
36
|
+
options?: {
|
|
37
|
+
prependPaths?: string[];
|
|
38
|
+
appendPaths?: string[];
|
|
39
|
+
}
|
|
40
|
+
): any {
|
|
34
41
|
if (typeof filename === 'object') {
|
|
35
42
|
options = filename;
|
|
36
43
|
filename = '';
|
|
37
44
|
}
|
|
38
45
|
|
|
39
|
-
options = {
|
|
40
|
-
appendPaths: [],
|
|
41
|
-
prependPaths: [],
|
|
42
|
-
...options
|
|
43
|
-
};
|
|
44
|
-
|
|
45
46
|
if (typeof code !== 'string') {
|
|
46
47
|
throw new Error(`code must be a string, not ${typeof code}`);
|
|
47
48
|
}
|
|
@@ -53,7 +54,10 @@ export function requireFromString(code, filename = '', options = {}) {
|
|
|
53
54
|
// @ts-ignore
|
|
54
55
|
const newModule = new Module(filename, parent);
|
|
55
56
|
newModule.filename = filename;
|
|
56
|
-
newModule.paths = []
|
|
57
|
+
newModule.paths = ([] as string[])
|
|
58
|
+
.concat(options?.prependPaths || [])
|
|
59
|
+
.concat(paths)
|
|
60
|
+
.concat(options?.appendPaths || []);
|
|
57
61
|
// @ts-ignore
|
|
58
62
|
newModule._compile(code, filename);
|
|
59
63
|
|
|
@@ -44,7 +44,7 @@ export default class ChildProcessProxy {
|
|
|
44
44
|
props: ChildProcessProxyProps = {...DEFAULT_PROPS};
|
|
45
45
|
private childProcess: ChildProcess.ChildProcess | null = null;
|
|
46
46
|
private port: number = 0;
|
|
47
|
-
private successTimer
|
|
47
|
+
private successTimer?: any; // NodeJS.Timeout;
|
|
48
48
|
|
|
49
49
|
// constructor(props?: {id?: string});
|
|
50
50
|
constructor({id = 'browser-driver'} = {}) {
|
|
@@ -11,10 +11,14 @@ import WorkerBody from '../worker-farm/worker-body';
|
|
|
11
11
|
|
|
12
12
|
/** Counter for jobs */
|
|
13
13
|
let requestId = 0;
|
|
14
|
-
let inputBatches
|
|
15
|
-
let options;
|
|
14
|
+
let inputBatches: AsyncQueue<any>;
|
|
15
|
+
let options: {[key: string]: any};
|
|
16
16
|
|
|
17
|
-
export type ProcessOnMainThread = (
|
|
17
|
+
export type ProcessOnMainThread = (
|
|
18
|
+
data: any,
|
|
19
|
+
options?: {[key: string]: any},
|
|
20
|
+
context?: WorkerContext
|
|
21
|
+
) => any;
|
|
18
22
|
|
|
19
23
|
/**
|
|
20
24
|
* Set up a WebWorkerGlobalScope to talk with the main thread
|
|
@@ -45,9 +49,9 @@ export function createWorker(process: Process, processInBatches?: ProcessInBatch
|
|
|
45
49
|
if (!processInBatches) {
|
|
46
50
|
throw new Error('Worker does not support batched processing');
|
|
47
51
|
}
|
|
48
|
-
inputBatches = new AsyncQueue();
|
|
52
|
+
inputBatches = new AsyncQueue<any>();
|
|
49
53
|
options = payload.options || {};
|
|
50
|
-
const resultIterator = processInBatches(inputBatches, options, context
|
|
54
|
+
const resultIterator = processInBatches(inputBatches, options, context);
|
|
51
55
|
for await (const batch of resultIterator) {
|
|
52
56
|
WorkerBody.postMessage('output-batch', {result: batch});
|
|
53
57
|
}
|
|
@@ -71,13 +75,13 @@ export function createWorker(process: Process, processInBatches?: ProcessInBatch
|
|
|
71
75
|
};
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
function processOnMainThread(arrayBuffer, options = {}) {
|
|
78
|
+
function processOnMainThread(arrayBuffer: ArrayBuffer, options = {}) {
|
|
75
79
|
return new Promise((resolve, reject) => {
|
|
76
80
|
const id = requestId++;
|
|
77
81
|
|
|
78
82
|
/**
|
|
79
83
|
*/
|
|
80
|
-
const onMessage = (type, payload) => {
|
|
84
|
+
const onMessage = (type: string, payload: WorkerMessagePayload) => {
|
|
81
85
|
if (payload.id !== id) {
|
|
82
86
|
// not ours
|
|
83
87
|
return;
|
|
@@ -29,7 +29,7 @@ export default class WorkerBody {
|
|
|
29
29
|
let onMessageWrapper = onMessageWrapperMap.get(onMessage);
|
|
30
30
|
|
|
31
31
|
if (!onMessageWrapper) {
|
|
32
|
-
onMessageWrapper = (message) => {
|
|
32
|
+
onMessageWrapper = (message: MessageEvent<any>) => {
|
|
33
33
|
if (!isKnownMessage(message)) {
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
@@ -70,7 +70,7 @@ export default class WorkerBody {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
// Filter out noise messages sent to workers
|
|
73
|
-
function isKnownMessage(message) {
|
|
73
|
+
function isKnownMessage(message: MessageEvent<any>) {
|
|
74
74
|
const {type, data} = message;
|
|
75
75
|
return (
|
|
76
76
|
type === 'message' &&
|
|
@@ -42,7 +42,7 @@ export default class WorkerJob {
|
|
|
42
42
|
/**
|
|
43
43
|
* Call to resolve the `result` Promise with the supplied value
|
|
44
44
|
*/
|
|
45
|
-
done(value): void {
|
|
45
|
+
done(value: any): void {
|
|
46
46
|
assert(this.isRunning);
|
|
47
47
|
this.isRunning = false;
|
|
48
48
|
this._resolve(value);
|
|
@@ -51,7 +51,7 @@ export default class WorkerJob {
|
|
|
51
51
|
/**
|
|
52
52
|
* Call to reject the `result` Promise with the supplied error
|
|
53
53
|
*/
|
|
54
|
-
error(error): void {
|
|
54
|
+
error(error: Error): void {
|
|
55
55
|
assert(this.isRunning);
|
|
56
56
|
this.isRunning = false;
|
|
57
57
|
this._reject(error);
|
|
@@ -73,7 +73,7 @@ export default class WorkerThread {
|
|
|
73
73
|
* Generate a standard Error from an ErrorEvent
|
|
74
74
|
* @param {ErrorEvent} event
|
|
75
75
|
*/
|
|
76
|
-
_getErrorFromErrorEvent(event) {
|
|
76
|
+
_getErrorFromErrorEvent(event: ErrorEvent): Error {
|
|
77
77
|
// Note Error object does not have the expected fields if loading failed completely
|
|
78
78
|
// https://developer.mozilla.org/en-US/docs/Web/API/Worker#Event_handlers
|
|
79
79
|
// https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent
|
|
@@ -105,7 +105,7 @@ export default class WorkerThread {
|
|
|
105
105
|
}
|
|
106
106
|
};
|
|
107
107
|
// This callback represents an uncaught exception in the worker thread
|
|
108
|
-
worker.onerror = (error) => {
|
|
108
|
+
worker.onerror = (error: ErrorEvent): void => {
|
|
109
109
|
this.onError(this._getErrorFromErrorEvent(error));
|
|
110
110
|
this.terminated = true;
|
|
111
111
|
};
|
|
@@ -9,7 +9,7 @@ export function removeNontransferableOptions(object: object): object {
|
|
|
9
9
|
return JSON.parse(stringifyJSON(object));
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
function stringifyJSON(v) {
|
|
12
|
+
function stringifyJSON(v: unknown) {
|
|
13
13
|
const cache = new Set();
|
|
14
14
|
return JSON.stringify(v, (key, value) => {
|
|
15
15
|
if (typeof value === 'object' && value !== null) {
|
package/src/types.ts
CHANGED
|
@@ -14,7 +14,7 @@ export type WorkerOptions = {
|
|
|
14
14
|
|
|
15
15
|
export type WorkerContext = {
|
|
16
16
|
process?: Process;
|
|
17
|
-
processInBatches
|
|
17
|
+
processInBatches?: ProcessInBatches;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
export type Process = (data: any, options?: {[key: string]: any}, context?: WorkerContext) => any;
|