@loaders.gl/worker-utils
Advanced tools
Comparing version 3.4.14 to 3.4.15
@@ -9,3 +9,3 @@ "use strict"; | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _asyncQueue.default; | ||
@@ -16,3 +16,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _childProcessProxy.default; | ||
@@ -24,3 +24,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _workerBody.default; | ||
@@ -31,3 +31,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _workerFarm.default; | ||
@@ -38,3 +38,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _workerJob.default; | ||
@@ -45,3 +45,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _workerPool.default; | ||
@@ -52,3 +52,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _workerThread.default; | ||
@@ -59,3 +59,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _assert.assert; | ||
@@ -66,3 +66,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _processOnWorker.canProcessOnWorker; | ||
@@ -73,3 +73,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _createWorker.createWorker; | ||
@@ -80,3 +80,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _libraryUtils.getLibraryUrl; | ||
@@ -87,3 +87,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _getTransferList.getTransferList; | ||
@@ -94,3 +94,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _getTransferList.getTransferListForWriter; | ||
@@ -101,3 +101,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _getWorkerUrl.getWorkerURL; | ||
@@ -108,3 +108,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _globals.isBrowser; | ||
@@ -115,3 +115,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _globals.isWorker; | ||
@@ -122,3 +122,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _libraryUtils.loadLibrary; | ||
@@ -129,3 +129,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _processOnWorker.processOnWorker; | ||
@@ -136,3 +136,3 @@ } | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return _validateWorkerVersion.validateWorkerVersion; | ||
@@ -157,3 +157,3 @@ } | ||
var _childProcessProxy = _interopRequireDefault(require("./lib/process-utils/child-process-proxy")); | ||
var NullWorker = { | ||
const NullWorker = { | ||
id: 'null', | ||
@@ -160,0 +160,0 @@ name: 'null', |
@@ -8,10 +8,7 @@ "use strict"; | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _Symbol$asyncIterator; | ||
let _Symbol$asyncIterator; | ||
_Symbol$asyncIterator = Symbol.asyncIterator; | ||
var AsyncQueue = function () { | ||
function AsyncQueue() { | ||
(0, _classCallCheck2.default)(this, AsyncQueue); | ||
class AsyncQueue { | ||
constructor() { | ||
(0, _defineProperty2.default)(this, "_values", void 0); | ||
@@ -24,79 +21,66 @@ (0, _defineProperty2.default)(this, "_settlers", void 0); | ||
} | ||
(0, _createClass2.default)(AsyncQueue, [{ | ||
key: _Symbol$asyncIterator, | ||
value: function value() { | ||
return this; | ||
[_Symbol$asyncIterator]() { | ||
return this; | ||
} | ||
push(value) { | ||
return this.enqueue(value); | ||
} | ||
enqueue(value) { | ||
if (this._closed) { | ||
throw new Error('Closed'); | ||
} | ||
}, { | ||
key: "push", | ||
value: function push(value) { | ||
return this.enqueue(value); | ||
} | ||
}, { | ||
key: "enqueue", | ||
value: function enqueue(value) { | ||
if (this._closed) { | ||
throw new Error('Closed'); | ||
if (this._settlers.length > 0) { | ||
if (this._values.length > 0) { | ||
throw new Error('Illegal internal state'); | ||
} | ||
if (this._settlers.length > 0) { | ||
if (this._values.length > 0) { | ||
throw new Error('Illegal internal state'); | ||
} | ||
var settler = this._settlers.shift(); | ||
if (value instanceof Error) { | ||
settler.reject(value); | ||
} else { | ||
settler.resolve({ | ||
value: value | ||
}); | ||
} | ||
const settler = this._settlers.shift(); | ||
if (value instanceof Error) { | ||
settler.reject(value); | ||
} else { | ||
this._values.push(value); | ||
} | ||
} | ||
}, { | ||
key: "close", | ||
value: function close() { | ||
while (this._settlers.length > 0) { | ||
var settler = this._settlers.shift(); | ||
settler.resolve({ | ||
done: true | ||
value | ||
}); | ||
} | ||
this._closed = true; | ||
} else { | ||
this._values.push(value); | ||
} | ||
}, { | ||
key: "next", | ||
value: function next() { | ||
var _this = this; | ||
if (this._values.length > 0) { | ||
var value = this._values.shift(); | ||
if (value instanceof Error) { | ||
return Promise.reject(value); | ||
} | ||
return Promise.resolve({ | ||
done: false, | ||
value: value | ||
}); | ||
} | ||
close() { | ||
while (this._settlers.length > 0) { | ||
const settler = this._settlers.shift(); | ||
settler.resolve({ | ||
done: true | ||
}); | ||
} | ||
this._closed = true; | ||
} | ||
next() { | ||
if (this._values.length > 0) { | ||
const value = this._values.shift(); | ||
if (value instanceof Error) { | ||
return Promise.reject(value); | ||
} | ||
if (this._closed) { | ||
if (this._settlers.length > 0) { | ||
throw new Error('Illegal internal state'); | ||
} | ||
return Promise.resolve({ | ||
done: true, | ||
value: undefined | ||
}); | ||
return Promise.resolve({ | ||
done: false, | ||
value | ||
}); | ||
} | ||
if (this._closed) { | ||
if (this._settlers.length > 0) { | ||
throw new Error('Illegal internal state'); | ||
} | ||
return new Promise(function (resolve, reject) { | ||
_this._settlers.push({ | ||
resolve: resolve, | ||
reject: reject | ||
}); | ||
return Promise.resolve({ | ||
done: true, | ||
value: undefined | ||
}); | ||
} | ||
}]); | ||
return AsyncQueue; | ||
}(); | ||
return new Promise((resolve, reject) => { | ||
this._settlers.push({ | ||
resolve, | ||
reject | ||
}); | ||
}); | ||
} | ||
} | ||
exports.default = AsyncQueue; | ||
//# sourceMappingURL=async-queue.js.map |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,4 +7,3 @@ value: true | ||
exports.window = exports.self = exports.nodeVersion = exports.isWorker = exports.isMobile = exports.isBrowser = exports.global = exports.document = void 0; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var globals = { | ||
const globals = { | ||
self: typeof self !== 'undefined' && self, | ||
@@ -16,19 +14,19 @@ window: typeof window !== 'undefined' && window, | ||
}; | ||
var self_ = globals.self || globals.window || globals.global || {}; | ||
const self_ = globals.self || globals.window || globals.global || {}; | ||
exports.self = self_; | ||
var window_ = globals.window || globals.self || globals.global || {}; | ||
const window_ = globals.window || globals.self || globals.global || {}; | ||
exports.window = window_; | ||
var global_ = globals.global || globals.self || globals.window || {}; | ||
const global_ = globals.global || globals.self || globals.window || {}; | ||
exports.global = global_; | ||
var document_ = globals.document || {}; | ||
const document_ = globals.document || {}; | ||
exports.document = document_; | ||
var isBrowser = (typeof process === "undefined" ? "undefined" : (0, _typeof2.default)(process)) !== 'object' || String(process) !== '[object process]' || process.browser; | ||
const isBrowser = typeof process !== 'object' || String(process) !== '[object process]' || process.browser; | ||
exports.isBrowser = isBrowser; | ||
var isWorker = typeof importScripts === 'function'; | ||
const isWorker = typeof importScripts === 'function'; | ||
exports.isWorker = isWorker; | ||
var isMobile = typeof window !== 'undefined' && typeof window.orientation !== 'undefined'; | ||
const isMobile = typeof window !== 'undefined' && typeof window.orientation !== 'undefined'; | ||
exports.isMobile = isMobile; | ||
var matches = typeof process !== 'undefined' && process.version && /v([0-9]*)/.exec(process.version); | ||
var nodeVersion = matches && parseFloat(matches[1]) || 0; | ||
const matches = typeof process !== 'undefined' && process.version && /v([0-9]*)/.exec(process.version); | ||
const nodeVersion = matches && parseFloat(matches[1]) || 0; | ||
exports.nodeVersion = nodeVersion; | ||
//# sourceMappingURL=globals.js.map |
@@ -7,8 +7,8 @@ "use strict"; | ||
exports.VERSION = void 0; | ||
var DEFAULT_VERSION = 'latest'; | ||
var VERSION = typeof "3.4.14" !== 'undefined' ? "3.4.14" : DEFAULT_VERSION; | ||
const DEFAULT_VERSION = 'latest'; | ||
const VERSION = typeof "3.4.15" !== 'undefined' ? "3.4.15" : DEFAULT_VERSION; | ||
exports.VERSION = VERSION; | ||
if (typeof "3.4.14" === 'undefined') { | ||
if (typeof "3.4.15" === 'undefined') { | ||
console.error('loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.'); | ||
} | ||
//# sourceMappingURL=version.js.map |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -10,4 +8,2 @@ value: true | ||
exports.loadLibrary = loadLibrary; | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _globals = require("../env-utils/globals"); | ||
@@ -17,36 +13,16 @@ var node = _interopRequireWildcard(require("../node/require-utils.node")); | ||
var _version = require("../env-utils/version"); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
var LATEST = 'latest'; | ||
var VERSION = typeof "3.4.14" !== 'undefined' ? "3.4.14" : LATEST; | ||
var loadLibraryPromises = {}; | ||
function loadLibrary(_x) { | ||
return _loadLibrary.apply(this, arguments); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
const LATEST = 'latest'; | ||
const VERSION = typeof "3.4.15" !== 'undefined' ? "3.4.15" : LATEST; | ||
const loadLibraryPromises = {}; | ||
async function loadLibrary(libraryUrl) { | ||
let moduleName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
if (moduleName) { | ||
libraryUrl = getLibraryUrl(libraryUrl, moduleName, options); | ||
} | ||
loadLibraryPromises[libraryUrl] = loadLibraryPromises[libraryUrl] || loadLibraryFromFile(libraryUrl); | ||
return await loadLibraryPromises[libraryUrl]; | ||
} | ||
function _loadLibrary() { | ||
_loadLibrary = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(libraryUrl) { | ||
var moduleName, | ||
options, | ||
_args = arguments; | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
moduleName = _args.length > 1 && _args[1] !== undefined ? _args[1] : null; | ||
options = _args.length > 2 && _args[2] !== undefined ? _args[2] : {}; | ||
if (moduleName) { | ||
libraryUrl = getLibraryUrl(libraryUrl, moduleName, options); | ||
} | ||
loadLibraryPromises[libraryUrl] = loadLibraryPromises[libraryUrl] || loadLibraryFromFile(libraryUrl); | ||
_context.next = 6; | ||
return loadLibraryPromises[libraryUrl]; | ||
case 6: | ||
return _context.abrupt("return", _context.sent); | ||
case 7: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee); | ||
})); | ||
return _loadLibrary.apply(this, arguments); | ||
} | ||
function getLibraryUrl(library, moduleName, options) { | ||
@@ -56,3 +32,3 @@ if (library.startsWith('http')) { | ||
} | ||
var modules = options.modules || {}; | ||
const modules = options.modules || {}; | ||
if (modules[library]) { | ||
@@ -73,68 +49,21 @@ return modules[library]; | ||
} | ||
function loadLibraryFromFile(_x2) { | ||
return _loadLibraryFromFile.apply(this, arguments); | ||
async function loadLibraryFromFile(libraryUrl) { | ||
if (libraryUrl.endsWith('wasm')) { | ||
const response = await fetch(libraryUrl); | ||
return await response.arrayBuffer(); | ||
} | ||
if (!_globals.isBrowser) { | ||
try { | ||
return node && node.requireFromFile && (await node.requireFromFile(libraryUrl)); | ||
} catch { | ||
return null; | ||
} | ||
} | ||
if (_globals.isWorker) { | ||
return importScripts(libraryUrl); | ||
} | ||
const response = await fetch(libraryUrl); | ||
const scriptSource = await response.text(); | ||
return loadLibraryFromString(scriptSource, libraryUrl); | ||
} | ||
function _loadLibraryFromFile() { | ||
_loadLibraryFromFile = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(libraryUrl) { | ||
var _response, response, scriptSource; | ||
return _regenerator.default.wrap(function _callee2$(_context2) { | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (!libraryUrl.endsWith('wasm')) { | ||
_context2.next = 7; | ||
break; | ||
} | ||
_context2.next = 3; | ||
return fetch(libraryUrl); | ||
case 3: | ||
_response = _context2.sent; | ||
_context2.next = 6; | ||
return _response.arrayBuffer(); | ||
case 6: | ||
return _context2.abrupt("return", _context2.sent); | ||
case 7: | ||
if (_globals.isBrowser) { | ||
_context2.next = 20; | ||
break; | ||
} | ||
_context2.prev = 8; | ||
_context2.t0 = node && node.requireFromFile; | ||
if (!_context2.t0) { | ||
_context2.next = 14; | ||
break; | ||
} | ||
_context2.next = 13; | ||
return node.requireFromFile(libraryUrl); | ||
case 13: | ||
_context2.t0 = _context2.sent; | ||
case 14: | ||
return _context2.abrupt("return", _context2.t0); | ||
case 17: | ||
_context2.prev = 17; | ||
_context2.t1 = _context2["catch"](8); | ||
return _context2.abrupt("return", null); | ||
case 20: | ||
if (!_globals.isWorker) { | ||
_context2.next = 22; | ||
break; | ||
} | ||
return _context2.abrupt("return", importScripts(libraryUrl)); | ||
case 22: | ||
_context2.next = 24; | ||
return fetch(libraryUrl); | ||
case 24: | ||
response = _context2.sent; | ||
_context2.next = 27; | ||
return response.text(); | ||
case 27: | ||
scriptSource = _context2.sent; | ||
return _context2.abrupt("return", loadLibraryFromString(scriptSource, libraryUrl)); | ||
case 29: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2, null, [[8, 17]]); | ||
})); | ||
return _loadLibraryFromFile.apply(this, arguments); | ||
} | ||
function loadLibraryFromString(scriptSource, id) { | ||
@@ -148,3 +77,3 @@ if (!_globals.isBrowser) { | ||
} | ||
var script = document.createElement('script'); | ||
const script = document.createElement('script'); | ||
script.id = id; | ||
@@ -151,0 +80,0 @@ try { |
@@ -7,10 +7,10 @@ "use strict"; | ||
exports.requireFromString = exports.requireFromFile = exports.readFileAsText = exports.readFileAsArrayBuffer = void 0; | ||
var readFileAsArrayBuffer = null; | ||
const readFileAsArrayBuffer = null; | ||
exports.readFileAsArrayBuffer = readFileAsArrayBuffer; | ||
var readFileAsText = null; | ||
const readFileAsText = null; | ||
exports.readFileAsText = readFileAsText; | ||
var requireFromFile = null; | ||
const requireFromFile = null; | ||
exports.requireFromFile = requireFromFile; | ||
var requireFromString = null; | ||
const requireFromString = null; | ||
exports.requireFromString = requireFromString; | ||
//# sourceMappingURL=require-utils.browser.js.map |
@@ -9,47 +9,20 @@ "use strict"; | ||
exports.requireFromString = requireFromString; | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _module = _interopRequireDefault(require("module")); | ||
var _path = _interopRequireDefault(require("path")); | ||
function requireFromFile(_x) { | ||
return _requireFromFile.apply(this, arguments); | ||
async function requireFromFile(filename) { | ||
if (filename.startsWith('http')) { | ||
const response = await fetch(filename); | ||
const code = await response.text(); | ||
return requireFromString(code); | ||
} | ||
if (!filename.startsWith('/')) { | ||
filename = "".concat(process.cwd(), "/").concat(filename); | ||
} | ||
return require(filename); | ||
} | ||
function _requireFromFile() { | ||
_requireFromFile = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(filename) { | ||
var response, code; | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!filename.startsWith('http')) { | ||
_context.next = 8; | ||
break; | ||
} | ||
_context.next = 3; | ||
return fetch(filename); | ||
case 3: | ||
response = _context.sent; | ||
_context.next = 6; | ||
return response.text(); | ||
case 6: | ||
code = _context.sent; | ||
return _context.abrupt("return", requireFromString(code)); | ||
case 8: | ||
if (!filename.startsWith('/')) { | ||
filename = "".concat(process.cwd(), "/").concat(filename); | ||
} | ||
return _context.abrupt("return", require(filename)); | ||
case 10: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee); | ||
})); | ||
return _requireFromFile.apply(this, arguments); | ||
} | ||
function requireFromString(code) { | ||
var _options, _options2; | ||
var filename = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | ||
var options = arguments.length > 2 ? arguments[2] : undefined; | ||
if ((0, _typeof2.default)(filename) === 'object') { | ||
let filename = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | ||
let options = arguments.length > 2 ? arguments[2] : undefined; | ||
if (typeof filename === 'object') { | ||
options = filename; | ||
@@ -59,7 +32,7 @@ filename = ''; | ||
if (typeof code !== 'string') { | ||
throw new Error("code must be a string, not ".concat((0, _typeof2.default)(code))); | ||
throw new Error("code must be a string, not ".concat(typeof code)); | ||
} | ||
var paths = _module.default._nodeModulePaths(_path.default.dirname(filename)); | ||
var parent = module.parent; | ||
var newModule = new _module.default(filename, parent); | ||
const paths = _module.default._nodeModulePaths(_path.default.dirname(filename)); | ||
const parent = module.parent; | ||
const newModule = new _module.default(filename, parent); | ||
newModule.filename = filename; | ||
@@ -66,0 +39,0 @@ 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) || []); |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,17 +7,8 @@ value: true | ||
exports.parentPort = exports.Worker = exports.NodeWorkerType = exports.NodeWorker = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var Worker = function () { | ||
function Worker() { | ||
(0, _classCallCheck2.default)(this, Worker); | ||
} | ||
(0, _createClass2.default)(Worker, [{ | ||
key: "terminate", | ||
value: function terminate() {} | ||
}]); | ||
return Worker; | ||
}(); | ||
class Worker { | ||
terminate() {} | ||
} | ||
exports.NodeWorkerType = exports.NodeWorker = exports.Worker = Worker; | ||
var parentPort = null; | ||
const parentPort = null; | ||
exports.parentPort = parentPort; | ||
//# sourceMappingURL=worker_threads-browser.js.map |
"use strict"; | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -18,3 +17,3 @@ value: true | ||
enumerable: true, | ||
get: function get() { | ||
get: function () { | ||
return WorkerThreads[key]; | ||
@@ -24,6 +23,6 @@ } | ||
}); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
var NodeWorker = WorkerThreads.Worker; | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
const NodeWorker = WorkerThreads.Worker; | ||
exports.NodeWorker = NodeWorker; | ||
//# sourceMappingURL=worker_threads.js.map |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _typeof = require("@babel/runtime/helpers/typeof"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,15 +8,8 @@ value: true | ||
exports.default = void 0; | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var ChildProcess = _interopRequireWildcard(require("child_process")); | ||
var _processUtils = require("./process-utils"); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
var DEFAULT_PROPS = { | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
const DEFAULT_PROPS = { | ||
command: '', | ||
@@ -28,14 +20,15 @@ arguments: [], | ||
wait: 2000, | ||
onSuccess: function onSuccess(processProxy) { | ||
onSuccess: processProxy => { | ||
console.log("Started ".concat(processProxy.props.command)); | ||
} | ||
}; | ||
var ChildProcessProxy = function () { | ||
function ChildProcessProxy() { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
_ref$id = _ref.id, | ||
id = _ref$id === void 0 ? 'browser-driver' : _ref$id; | ||
(0, _classCallCheck2.default)(this, ChildProcessProxy); | ||
class ChildProcessProxy { | ||
constructor() { | ||
let { | ||
id = 'browser-driver' | ||
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
(0, _defineProperty2.default)(this, "id", void 0); | ||
(0, _defineProperty2.default)(this, "props", _objectSpread({}, DEFAULT_PROPS)); | ||
(0, _defineProperty2.default)(this, "props", { | ||
...DEFAULT_PROPS | ||
}); | ||
(0, _defineProperty2.default)(this, "childProcess", null); | ||
@@ -46,153 +39,81 @@ (0, _defineProperty2.default)(this, "port", 0); | ||
} | ||
(0, _createClass2.default)(ChildProcessProxy, [{ | ||
key: "start", | ||
value: function () { | ||
var _start = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(props) { | ||
var _this = this; | ||
var args; | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
props = _objectSpread(_objectSpread({}, DEFAULT_PROPS), props); | ||
this.props = props; | ||
args = (0, _toConsumableArray2.default)(props.arguments); | ||
this.port = Number(props.port); | ||
if (!props.portArg) { | ||
_context.next = 10; | ||
break; | ||
} | ||
if (!props.autoPort) { | ||
_context.next = 9; | ||
break; | ||
} | ||
_context.next = 8; | ||
return (0, _processUtils.getAvailablePort)(props.port); | ||
case 8: | ||
this.port = _context.sent; | ||
case 9: | ||
args.push(props.portArg, String(this.port)); | ||
case 10: | ||
_context.next = 12; | ||
return new Promise(function (resolve, reject) { | ||
try { | ||
_this._setTimeout(function () { | ||
if (props.onSuccess) { | ||
props.onSuccess(_this); | ||
} | ||
resolve({}); | ||
}); | ||
console.log("Spawning ".concat(props.command, " ").concat(props.arguments.join(' '))); | ||
var childProcess = ChildProcess.spawn(props.command, args, props.spawn); | ||
_this.childProcess = childProcess; | ||
childProcess.stdout.on('data', function (data) { | ||
console.log(data.toString()); | ||
}); | ||
childProcess.stderr.on('data', function (data) { | ||
console.log("Child process wrote to stderr: \"".concat(data, "\".")); | ||
if (!props.ignoreStderr) { | ||
_this._clearTimeout(); | ||
reject(new Error(data)); | ||
} | ||
}); | ||
childProcess.on('error', function (error) { | ||
console.log("Child process errored with ".concat(error)); | ||
_this._clearTimeout(); | ||
reject(error); | ||
}); | ||
childProcess.on('close', function (code) { | ||
console.log("Child process exited with ".concat(code)); | ||
_this.childProcess = null; | ||
_this._clearTimeout(); | ||
resolve({}); | ||
}); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
case 12: | ||
return _context.abrupt("return", _context.sent); | ||
case 13: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, this); | ||
})); | ||
function start(_x) { | ||
return _start.apply(this, arguments); | ||
async start(props) { | ||
props = { | ||
...DEFAULT_PROPS, | ||
...props | ||
}; | ||
this.props = props; | ||
const args = [...props.arguments]; | ||
this.port = Number(props.port); | ||
if (props.portArg) { | ||
if (props.autoPort) { | ||
this.port = await (0, _processUtils.getAvailablePort)(props.port); | ||
} | ||
return start; | ||
}() | ||
}, { | ||
key: "stop", | ||
value: function () { | ||
var _stop = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2() { | ||
return _regenerator.default.wrap(function _callee2$(_context2) { | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (this.childProcess) { | ||
this.childProcess.kill(); | ||
this.childProcess = null; | ||
} | ||
case 1: | ||
case "end": | ||
return _context2.stop(); | ||
args.push(props.portArg, String(this.port)); | ||
} | ||
return await new Promise((resolve, reject) => { | ||
try { | ||
this._setTimeout(() => { | ||
if (props.onSuccess) { | ||
props.onSuccess(this); | ||
} | ||
}, _callee2, this); | ||
})); | ||
function stop() { | ||
return _stop.apply(this, arguments); | ||
} | ||
return stop; | ||
}() | ||
}, { | ||
key: "exit", | ||
value: function () { | ||
var _exit = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee3() { | ||
var statusCode, | ||
_args3 = arguments; | ||
return _regenerator.default.wrap(function _callee3$(_context3) { | ||
while (1) switch (_context3.prev = _context3.next) { | ||
case 0: | ||
statusCode = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : 0; | ||
_context3.prev = 1; | ||
_context3.next = 4; | ||
return this.stop(); | ||
case 4: | ||
process.exit(statusCode); | ||
_context3.next = 11; | ||
break; | ||
case 7: | ||
_context3.prev = 7; | ||
_context3.t0 = _context3["catch"](1); | ||
console.error(_context3.t0.message || _context3.t0); | ||
process.exit(1); | ||
case 11: | ||
case "end": | ||
return _context3.stop(); | ||
resolve({}); | ||
}); | ||
console.log("Spawning ".concat(props.command, " ").concat(props.arguments.join(' '))); | ||
const childProcess = ChildProcess.spawn(props.command, args, props.spawn); | ||
this.childProcess = childProcess; | ||
childProcess.stdout.on('data', data => { | ||
console.log(data.toString()); | ||
}); | ||
childProcess.stderr.on('data', data => { | ||
console.log("Child process wrote to stderr: \"".concat(data, "\".")); | ||
if (!props.ignoreStderr) { | ||
this._clearTimeout(); | ||
reject(new Error(data)); | ||
} | ||
}, _callee3, this, [[1, 7]]); | ||
})); | ||
function exit() { | ||
return _exit.apply(this, arguments); | ||
}); | ||
childProcess.on('error', error => { | ||
console.log("Child process errored with ".concat(error)); | ||
this._clearTimeout(); | ||
reject(error); | ||
}); | ||
childProcess.on('close', code => { | ||
console.log("Child process exited with ".concat(code)); | ||
this.childProcess = null; | ||
this._clearTimeout(); | ||
resolve({}); | ||
}); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
return exit; | ||
}() | ||
}, { | ||
key: "_setTimeout", | ||
value: function _setTimeout(callback) { | ||
if (Number(this.props.wait) > 0) { | ||
this.successTimer = setTimeout(callback, this.props.wait); | ||
} | ||
}); | ||
} | ||
async stop() { | ||
if (this.childProcess) { | ||
this.childProcess.kill(); | ||
this.childProcess = null; | ||
} | ||
}, { | ||
key: "_clearTimeout", | ||
value: function _clearTimeout() { | ||
if (this.successTimer) { | ||
clearTimeout(this.successTimer); | ||
} | ||
} | ||
async exit() { | ||
let statusCode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
try { | ||
await this.stop(); | ||
process.exit(statusCode); | ||
} catch (error) { | ||
console.error(error.message || error); | ||
process.exit(1); | ||
} | ||
}]); | ||
return ChildProcessProxy; | ||
}(); | ||
} | ||
_setTimeout(callback) { | ||
if (Number(this.props.wait) > 0) { | ||
this.successTimer = setTimeout(callback, this.props.wait); | ||
} | ||
} | ||
_clearTimeout() { | ||
if (this.successTimer) { | ||
clearTimeout(this.successTimer); | ||
} | ||
} | ||
} | ||
exports.default = ChildProcessProxy; | ||
//# sourceMappingURL=child-process-proxy.js.map |
@@ -10,5 +10,5 @@ "use strict"; | ||
function getAvailablePort() { | ||
var defaultPort = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 3000; | ||
return new Promise(function (resolve) { | ||
_child_process.default.exec('lsof -i -P -n | grep LISTEN', function (error, stdout) { | ||
let defaultPort = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 3000; | ||
return new Promise(resolve => { | ||
_child_process.default.exec('lsof -i -P -n | grep LISTEN', (error, stdout) => { | ||
if (error) { | ||
@@ -18,6 +18,6 @@ resolve(defaultPort); | ||
} | ||
var portsInUse = []; | ||
var regex = /:(\d+) \(LISTEN\)/; | ||
stdout.split('\n').forEach(function (line) { | ||
var match = regex.exec(line); | ||
const portsInUse = []; | ||
const regex = /:(\d+) \(LISTEN\)/; | ||
stdout.split('\n').forEach(line => { | ||
const match = regex.exec(line); | ||
if (match) { | ||
@@ -27,3 +27,3 @@ portsInUse.push(Number(match[1])); | ||
}); | ||
var port = defaultPort; | ||
let port = defaultPort; | ||
while (portsInUse.includes(port)) { | ||
@@ -30,0 +30,0 @@ port++; |
@@ -8,11 +8,7 @@ "use strict"; | ||
exports.createWorker = createWorker; | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _asyncQueue = _interopRequireDefault(require("../async-queue/async-queue")); | ||
var _workerBody = _interopRequireDefault(require("../worker-farm/worker-body")); | ||
function _asyncIterator(iterable) { var method, async, sync, retry = 2; for ("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;) { if (async && null != (method = iterable[async])) return method.call(iterable); if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable)); async = "@@asyncIterator", sync = "@@iterator"; } throw new TypeError("Object is not async iterable"); } | ||
function AsyncFromSyncIterator(s) { function AsyncFromSyncIteratorContinuation(r) { if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object.")); var done = r.done; return Promise.resolve(r.value).then(function (value) { return { value: value, done: done }; }); } return AsyncFromSyncIterator = function AsyncFromSyncIterator(s) { this.s = s, this.n = s.next; }, AsyncFromSyncIterator.prototype = { s: null, n: null, next: function next() { return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments)); }, return: function _return(value) { var ret = this.s.return; return void 0 === ret ? Promise.resolve({ value: value, done: !0 }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments)); }, throw: function _throw(value) { var thr = this.s.return; return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments)); } }, new AsyncFromSyncIterator(s); } | ||
var requestId = 0; | ||
var inputBatches; | ||
var options; | ||
let requestId = 0; | ||
let inputBatches; | ||
let options; | ||
function createWorker(process, processInBatches) { | ||
@@ -22,123 +18,52 @@ if (!_workerBody.default.inWorkerThread()) { | ||
} | ||
var context = { | ||
const context = { | ||
process: processOnMainThread | ||
}; | ||
_workerBody.default.onmessage = function () { | ||
var _ref = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(type, payload) { | ||
var result, resultIterator, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, batch, message; | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.prev = 0; | ||
_context.t0 = type; | ||
_context.next = _context.t0 === 'process' ? 4 : _context.t0 === 'process-in-batches' ? 11 : _context.t0 === 'input-batch' ? 46 : _context.t0 === 'input-done' ? 48 : 50; | ||
break; | ||
case 4: | ||
if (process) { | ||
_context.next = 6; | ||
break; | ||
} | ||
_workerBody.default.onmessage = async (type, payload) => { | ||
try { | ||
switch (type) { | ||
case 'process': | ||
if (!process) { | ||
throw new Error('Worker does not support atomic processing'); | ||
case 6: | ||
_context.next = 8; | ||
return process(payload.input, payload.options || {}, context); | ||
case 8: | ||
result = _context.sent; | ||
_workerBody.default.postMessage('done', { | ||
result: result | ||
}); | ||
return _context.abrupt("break", 50); | ||
case 11: | ||
if (processInBatches) { | ||
_context.next = 13; | ||
break; | ||
} | ||
} | ||
const result = await process(payload.input, payload.options || {}, context); | ||
_workerBody.default.postMessage('done', { | ||
result | ||
}); | ||
break; | ||
case 'process-in-batches': | ||
if (!processInBatches) { | ||
throw new Error('Worker does not support batched processing'); | ||
case 13: | ||
inputBatches = new _asyncQueue.default(); | ||
options = payload.options || {}; | ||
resultIterator = processInBatches(inputBatches, options, context); | ||
_iteratorAbruptCompletion = false; | ||
_didIteratorError = false; | ||
_context.prev = 18; | ||
_iterator = _asyncIterator(resultIterator); | ||
case 20: | ||
_context.next = 22; | ||
return _iterator.next(); | ||
case 22: | ||
if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) { | ||
_context.next = 28; | ||
break; | ||
} | ||
batch = _step.value; | ||
} | ||
inputBatches = new _asyncQueue.default(); | ||
options = payload.options || {}; | ||
const resultIterator = processInBatches(inputBatches, options, context); | ||
for await (const batch of resultIterator) { | ||
_workerBody.default.postMessage('output-batch', { | ||
result: batch | ||
}); | ||
case 25: | ||
_iteratorAbruptCompletion = false; | ||
_context.next = 20; | ||
break; | ||
case 28: | ||
_context.next = 34; | ||
break; | ||
case 30: | ||
_context.prev = 30; | ||
_context.t1 = _context["catch"](18); | ||
_didIteratorError = true; | ||
_iteratorError = _context.t1; | ||
case 34: | ||
_context.prev = 34; | ||
_context.prev = 35; | ||
if (!(_iteratorAbruptCompletion && _iterator.return != null)) { | ||
_context.next = 39; | ||
break; | ||
} | ||
_context.next = 39; | ||
return _iterator.return(); | ||
case 39: | ||
_context.prev = 39; | ||
if (!_didIteratorError) { | ||
_context.next = 42; | ||
break; | ||
} | ||
throw _iteratorError; | ||
case 42: | ||
return _context.finish(39); | ||
case 43: | ||
return _context.finish(34); | ||
case 44: | ||
_workerBody.default.postMessage('done', {}); | ||
return _context.abrupt("break", 50); | ||
case 46: | ||
inputBatches.push(payload.input); | ||
return _context.abrupt("break", 50); | ||
case 48: | ||
inputBatches.close(); | ||
return _context.abrupt("break", 50); | ||
case 50: | ||
_context.next = 56; | ||
break; | ||
case 52: | ||
_context.prev = 52; | ||
_context.t2 = _context["catch"](0); | ||
message = _context.t2 instanceof Error ? _context.t2.message : ''; | ||
_workerBody.default.postMessage('error', { | ||
error: message | ||
}); | ||
case 56: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, null, [[0, 52], [18, 30, 34, 44], [35,, 39, 43]]); | ||
})); | ||
return function (_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
} | ||
_workerBody.default.postMessage('done', {}); | ||
break; | ||
case 'input-batch': | ||
inputBatches.push(payload.input); | ||
break; | ||
case 'input-done': | ||
inputBatches.close(); | ||
break; | ||
default: | ||
} | ||
} catch (error) { | ||
const message = error instanceof Error ? error.message : ''; | ||
_workerBody.default.postMessage('error', { | ||
error: message | ||
}); | ||
} | ||
}; | ||
} | ||
function processOnMainThread(arrayBuffer) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return new Promise(function (resolve, reject) { | ||
var id = requestId++; | ||
var onMessage = function onMessage(type, payload) { | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return new Promise((resolve, reject) => { | ||
const id = requestId++; | ||
const onMessage = (type, payload) => { | ||
if (payload.id !== id) { | ||
@@ -160,6 +85,6 @@ return; | ||
_workerBody.default.addEventListener(onMessage); | ||
var payload = { | ||
id: id, | ||
const payload = { | ||
id, | ||
input: arrayBuffer, | ||
options: options | ||
options | ||
}; | ||
@@ -166,0 +91,0 @@ _workerBody.default.postMessage('process', payload); |
@@ -10,13 +10,13 @@ "use strict"; | ||
var _version = require("../env-utils/version"); | ||
var NPM_TAG = 'latest'; | ||
var VERSION = typeof "3.4.14" !== 'undefined' ? "3.4.14" : NPM_TAG; | ||
const NPM_TAG = 'latest'; | ||
const VERSION = typeof "3.4.15" !== 'undefined' ? "3.4.15" : NPM_TAG; | ||
function getWorkerName(worker) { | ||
var warning = worker.version !== VERSION ? " (worker-utils@".concat(VERSION, ")") : ''; | ||
const warning = worker.version !== VERSION ? " (worker-utils@".concat(VERSION, ")") : ''; | ||
return "".concat(worker.name, "@").concat(worker.version).concat(warning); | ||
} | ||
function getWorkerURL(worker) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var workerOptions = options[worker.id] || {}; | ||
var workerFile = "".concat(worker.id, "-worker.js"); | ||
var url = workerOptions.workerUrl; | ||
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
const workerOptions = options[worker.id] || {}; | ||
const workerFile = "".concat(worker.id, "-worker.js"); | ||
let url = workerOptions.workerUrl; | ||
if (!url && worker.id === 'compression') { | ||
@@ -29,7 +29,7 @@ url = options.workerUrl; | ||
if (!url) { | ||
var version = worker.version; | ||
let version = worker.version; | ||
if (version === 'latest') { | ||
version = NPM_TAG; | ||
} | ||
var versionTag = version ? "@".concat(version) : ''; | ||
const versionTag = version ? "@".concat(version) : ''; | ||
url = "https://unpkg.com/@loaders.gl/".concat(worker.module).concat(versionTag, "/dist/").concat(workerFile); | ||
@@ -36,0 +36,0 @@ } |
@@ -9,4 +9,2 @@ "use strict"; | ||
exports.processOnWorker = processOnWorker; | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _workerFarm = _interopRequireDefault(require("../worker-farm/worker-farm")); | ||
@@ -21,119 +19,67 @@ var _getWorkerUrl = require("./get-worker-url"); | ||
} | ||
function processOnWorker(_x, _x2) { | ||
return _processOnWorker.apply(this, arguments); | ||
async function processOnWorker(worker, data) { | ||
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
let context = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
const name = (0, _getWorkerUrl.getWorkerName)(worker); | ||
const workerFarm = _workerFarm.default.getWorkerFarm(options); | ||
const { | ||
source | ||
} = options; | ||
const workerPoolProps = { | ||
name, | ||
source | ||
}; | ||
if (!source) { | ||
workerPoolProps.url = (0, _getWorkerUrl.getWorkerURL)(worker, options); | ||
} | ||
const workerPool = workerFarm.getWorkerPool(workerPoolProps); | ||
const jobName = options.jobName || worker.name; | ||
const job = await workerPool.startJob(jobName, onMessage.bind(null, context)); | ||
const transferableOptions = (0, _getTransferList.getTransferListForWriter)(options); | ||
job.postMessage('process', { | ||
input: data, | ||
options: transferableOptions | ||
}); | ||
const result = await job.result; | ||
return result.result; | ||
} | ||
function _processOnWorker() { | ||
_processOnWorker = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(worker, data) { | ||
var options, | ||
context, | ||
name, | ||
workerFarm, | ||
source, | ||
workerPoolProps, | ||
workerPool, | ||
jobName, | ||
job, | ||
transferableOptions, | ||
result, | ||
_args = arguments; | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
options = _args.length > 2 && _args[2] !== undefined ? _args[2] : {}; | ||
context = _args.length > 3 && _args[3] !== undefined ? _args[3] : {}; | ||
name = (0, _getWorkerUrl.getWorkerName)(worker); | ||
workerFarm = _workerFarm.default.getWorkerFarm(options); | ||
source = options.source; | ||
workerPoolProps = { | ||
name: name, | ||
source: source | ||
}; | ||
if (!source) { | ||
workerPoolProps.url = (0, _getWorkerUrl.getWorkerURL)(worker, options); | ||
} | ||
workerPool = workerFarm.getWorkerPool(workerPoolProps); | ||
jobName = options.jobName || worker.name; | ||
_context.next = 11; | ||
return workerPool.startJob(jobName, onMessage.bind(null, context)); | ||
case 11: | ||
job = _context.sent; | ||
transferableOptions = (0, _getTransferList.getTransferListForWriter)(options); | ||
job.postMessage('process', { | ||
input: data, | ||
options: transferableOptions | ||
}); | ||
_context.next = 16; | ||
return job.result; | ||
case 16: | ||
result = _context.sent; | ||
return _context.abrupt("return", result.result); | ||
case 18: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee); | ||
})); | ||
return _processOnWorker.apply(this, arguments); | ||
} | ||
function onMessage(_x3, _x4, _x5, _x6) { | ||
return _onMessage.apply(this, arguments); | ||
} | ||
function _onMessage() { | ||
_onMessage = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2(context, job, type, payload) { | ||
var id, input, options, result, message; | ||
return _regenerator.default.wrap(function _callee2$(_context2) { | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.t0 = type; | ||
_context2.next = _context2.t0 === 'done' ? 3 : _context2.t0 === 'error' ? 5 : _context2.t0 === 'process' ? 7 : 23; | ||
break; | ||
case 3: | ||
job.done(payload); | ||
return _context2.abrupt("break", 24); | ||
case 5: | ||
job.error(new Error(payload.error)); | ||
return _context2.abrupt("break", 24); | ||
case 7: | ||
id = payload.id, input = payload.input, options = payload.options; | ||
_context2.prev = 8; | ||
if (context.process) { | ||
_context2.next = 12; | ||
break; | ||
} | ||
async function onMessage(context, job, type, payload) { | ||
switch (type) { | ||
case 'done': | ||
job.done(payload); | ||
break; | ||
case 'error': | ||
job.error(new Error(payload.error)); | ||
break; | ||
case 'process': | ||
const { | ||
id, | ||
input, | ||
options | ||
} = payload; | ||
try { | ||
if (!context.process) { | ||
job.postMessage('error', { | ||
id: id, | ||
id, | ||
error: 'Worker not set up to process on main thread' | ||
}); | ||
return _context2.abrupt("return"); | ||
case 12: | ||
_context2.next = 14; | ||
return context.process(input, options); | ||
case 14: | ||
result = _context2.sent; | ||
job.postMessage('done', { | ||
id: id, | ||
result: result | ||
}); | ||
_context2.next = 22; | ||
break; | ||
case 18: | ||
_context2.prev = 18; | ||
_context2.t1 = _context2["catch"](8); | ||
message = _context2.t1 instanceof Error ? _context2.t1.message : 'unknown error'; | ||
job.postMessage('error', { | ||
id: id, | ||
error: message | ||
}); | ||
case 22: | ||
return _context2.abrupt("break", 24); | ||
case 23: | ||
console.warn("process-on-worker: unknown message ".concat(type)); | ||
case 24: | ||
case "end": | ||
return _context2.stop(); | ||
return; | ||
} | ||
const result = await context.process(input, options); | ||
job.postMessage('done', { | ||
id, | ||
result | ||
}); | ||
} catch (error) { | ||
const message = error instanceof Error ? error.message : 'unknown error'; | ||
job.postMessage('error', { | ||
id, | ||
error: message | ||
}); | ||
} | ||
}, _callee2, null, [[8, 18]]); | ||
})); | ||
return _onMessage.apply(this, arguments); | ||
break; | ||
default: | ||
console.warn("process-on-worker: unknown message ".concat(type)); | ||
} | ||
} | ||
//# sourceMappingURL=process-on-worker.js.map |
@@ -10,5 +10,5 @@ "use strict"; | ||
function validateWorkerVersion(worker) { | ||
var coreVersion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _version.VERSION; | ||
let coreVersion = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _version.VERSION; | ||
(0, _assert.assert)(worker, 'no worker provided'); | ||
var workerVersion = worker.version; | ||
const workerVersion = worker.version; | ||
if (!coreVersion || !workerVersion) { | ||
@@ -20,3 +20,3 @@ return false; | ||
function parseVersion(version) { | ||
var parts = version.split('.').map(Number); | ||
const parts = version.split('.').map(Number); | ||
return { | ||
@@ -23,0 +23,0 @@ major: parts[0], |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,103 +7,88 @@ value: true | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _getTransferList = require("../worker-utils/get-transfer-list"); | ||
function getParentPort() { | ||
var parentPort; | ||
let parentPort; | ||
try { | ||
eval('globalThis.parentPort = require(\'worker_threads\').parentPort'); | ||
parentPort = globalThis.parentPort; | ||
} catch (_unused) {} | ||
} catch {} | ||
return parentPort; | ||
} | ||
var onMessageWrapperMap = new Map(); | ||
var WorkerBody = function () { | ||
function WorkerBody() { | ||
(0, _classCallCheck2.default)(this, WorkerBody); | ||
const onMessageWrapperMap = new Map(); | ||
class WorkerBody { | ||
static inWorkerThread() { | ||
return typeof self !== 'undefined' || Boolean(getParentPort()); | ||
} | ||
(0, _createClass2.default)(WorkerBody, null, [{ | ||
key: "inWorkerThread", | ||
value: function inWorkerThread() { | ||
return typeof self !== 'undefined' || Boolean(getParentPort()); | ||
static set onmessage(onMessage) { | ||
function handleMessage(message) { | ||
const parentPort = getParentPort(); | ||
const { | ||
type, | ||
payload | ||
} = parentPort ? message : message.data; | ||
onMessage(type, payload); | ||
} | ||
}, { | ||
key: "onmessage", | ||
set: function set(onMessage) { | ||
function handleMessage(message) { | ||
var parentPort = getParentPort(); | ||
var _ref = parentPort ? message : message.data, | ||
type = _ref.type, | ||
payload = _ref.payload; | ||
const parentPort = getParentPort(); | ||
if (parentPort) { | ||
parentPort.on('message', handleMessage); | ||
parentPort.on('exit', () => console.debug('Node worker closing')); | ||
} else { | ||
globalThis.onmessage = handleMessage; | ||
} | ||
} | ||
static addEventListener(onMessage) { | ||
let onMessageWrapper = onMessageWrapperMap.get(onMessage); | ||
if (!onMessageWrapper) { | ||
onMessageWrapper = message => { | ||
if (!isKnownMessage(message)) { | ||
return; | ||
} | ||
const parentPort = getParentPort(); | ||
const { | ||
type, | ||
payload | ||
} = parentPort ? message : message.data; | ||
onMessage(type, payload); | ||
} | ||
var parentPort = getParentPort(); | ||
if (parentPort) { | ||
parentPort.on('message', handleMessage); | ||
parentPort.on('exit', function () { | ||
return console.debug('Node worker closing'); | ||
}); | ||
} else { | ||
globalThis.onmessage = handleMessage; | ||
} | ||
}; | ||
} | ||
}, { | ||
key: "addEventListener", | ||
value: function addEventListener(onMessage) { | ||
var onMessageWrapper = onMessageWrapperMap.get(onMessage); | ||
if (!onMessageWrapper) { | ||
onMessageWrapper = function onMessageWrapper(message) { | ||
if (!isKnownMessage(message)) { | ||
return; | ||
} | ||
var parentPort = getParentPort(); | ||
var _ref2 = parentPort ? message : message.data, | ||
type = _ref2.type, | ||
payload = _ref2.payload; | ||
onMessage(type, payload); | ||
}; | ||
} | ||
var parentPort = getParentPort(); | ||
if (parentPort) { | ||
console.error('not implemented'); | ||
} else { | ||
globalThis.addEventListener('message', onMessageWrapper); | ||
} | ||
const parentPort = getParentPort(); | ||
if (parentPort) { | ||
console.error('not implemented'); | ||
} else { | ||
globalThis.addEventListener('message', onMessageWrapper); | ||
} | ||
}, { | ||
key: "removeEventListener", | ||
value: function removeEventListener(onMessage) { | ||
var onMessageWrapper = onMessageWrapperMap.get(onMessage); | ||
onMessageWrapperMap.delete(onMessage); | ||
var parentPort = getParentPort(); | ||
if (parentPort) { | ||
console.error('not implemented'); | ||
} else { | ||
globalThis.removeEventListener('message', onMessageWrapper); | ||
} | ||
} | ||
static removeEventListener(onMessage) { | ||
const onMessageWrapper = onMessageWrapperMap.get(onMessage); | ||
onMessageWrapperMap.delete(onMessage); | ||
const parentPort = getParentPort(); | ||
if (parentPort) { | ||
console.error('not implemented'); | ||
} else { | ||
globalThis.removeEventListener('message', onMessageWrapper); | ||
} | ||
}, { | ||
key: "postMessage", | ||
value: function postMessage(type, payload) { | ||
var data = { | ||
source: 'loaders.gl', | ||
type: type, | ||
payload: payload | ||
}; | ||
var transferList = (0, _getTransferList.getTransferList)(payload); | ||
var parentPort = getParentPort(); | ||
if (parentPort) { | ||
parentPort.postMessage(data, transferList); | ||
} else { | ||
globalThis.postMessage(data, transferList); | ||
} | ||
} | ||
static postMessage(type, payload) { | ||
const data = { | ||
source: 'loaders.gl', | ||
type, | ||
payload | ||
}; | ||
const transferList = (0, _getTransferList.getTransferList)(payload); | ||
const parentPort = getParentPort(); | ||
if (parentPort) { | ||
parentPort.postMessage(data, transferList); | ||
} else { | ||
globalThis.postMessage(data, transferList); | ||
} | ||
}]); | ||
return WorkerBody; | ||
}(); | ||
} | ||
} | ||
exports.default = WorkerBody; | ||
function isKnownMessage(message) { | ||
var type = message.type, | ||
data = message.data; | ||
const { | ||
type, | ||
data | ||
} = message; | ||
return type === 'message' && data && typeof data.source === 'string' && data.source.startsWith('loaders.gl'); | ||
} | ||
//# sourceMappingURL=worker-body.js.map |
@@ -8,107 +8,74 @@ "use strict"; | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _workerPool = _interopRequireDefault(require("./worker-pool")); | ||
var _workerThread = _interopRequireDefault(require("./worker-thread")); | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
var DEFAULT_PROPS = { | ||
const DEFAULT_PROPS = { | ||
maxConcurrency: 3, | ||
maxMobileConcurrency: 1, | ||
reuseWorkers: true, | ||
onDebug: function onDebug() {} | ||
onDebug: () => {} | ||
}; | ||
var WorkerFarm = function () { | ||
function WorkerFarm(props) { | ||
(0, _classCallCheck2.default)(this, WorkerFarm); | ||
class WorkerFarm { | ||
static isSupported() { | ||
return _workerThread.default.isSupported(); | ||
} | ||
static getWorkerFarm() { | ||
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
WorkerFarm._workerFarm = WorkerFarm._workerFarm || new WorkerFarm({}); | ||
WorkerFarm._workerFarm.setProps(props); | ||
return WorkerFarm._workerFarm; | ||
} | ||
constructor(props) { | ||
(0, _defineProperty2.default)(this, "props", void 0); | ||
(0, _defineProperty2.default)(this, "workerPools", new Map()); | ||
this.props = _objectSpread({}, DEFAULT_PROPS); | ||
this.props = { | ||
...DEFAULT_PROPS | ||
}; | ||
this.setProps(props); | ||
this.workerPools = new Map(); | ||
} | ||
(0, _createClass2.default)(WorkerFarm, [{ | ||
key: "destroy", | ||
value: function destroy() { | ||
var _iterator = _createForOfIteratorHelper(this.workerPools.values()), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var workerPool = _step.value; | ||
workerPool.destroy(); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
this.workerPools = new Map(); | ||
destroy() { | ||
for (const workerPool of this.workerPools.values()) { | ||
workerPool.destroy(); | ||
} | ||
}, { | ||
key: "setProps", | ||
value: function setProps(props) { | ||
this.props = _objectSpread(_objectSpread({}, this.props), props); | ||
var _iterator2 = _createForOfIteratorHelper(this.workerPools.values()), | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var workerPool = _step2.value; | ||
workerPool.setProps(this._getWorkerPoolProps()); | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
this.workerPools = new Map(); | ||
} | ||
setProps(props) { | ||
this.props = { | ||
...this.props, | ||
...props | ||
}; | ||
for (const workerPool of this.workerPools.values()) { | ||
workerPool.setProps(this._getWorkerPoolProps()); | ||
} | ||
}, { | ||
key: "getWorkerPool", | ||
value: function getWorkerPool(options) { | ||
var name = options.name, | ||
source = options.source, | ||
url = options.url; | ||
var workerPool = this.workerPools.get(name); | ||
if (!workerPool) { | ||
workerPool = new _workerPool.default({ | ||
name: name, | ||
source: source, | ||
url: url | ||
}); | ||
workerPool.setProps(this._getWorkerPoolProps()); | ||
this.workerPools.set(name, workerPool); | ||
} | ||
return workerPool; | ||
} | ||
getWorkerPool(options) { | ||
const { | ||
name, | ||
source, | ||
url | ||
} = options; | ||
let workerPool = this.workerPools.get(name); | ||
if (!workerPool) { | ||
workerPool = new _workerPool.default({ | ||
name, | ||
source, | ||
url | ||
}); | ||
workerPool.setProps(this._getWorkerPoolProps()); | ||
this.workerPools.set(name, workerPool); | ||
} | ||
}, { | ||
key: "_getWorkerPoolProps", | ||
value: function _getWorkerPoolProps() { | ||
return { | ||
maxConcurrency: this.props.maxConcurrency, | ||
maxMobileConcurrency: this.props.maxMobileConcurrency, | ||
reuseWorkers: this.props.reuseWorkers, | ||
onDebug: this.props.onDebug | ||
}; | ||
} | ||
}], [{ | ||
key: "isSupported", | ||
value: function isSupported() { | ||
return _workerThread.default.isSupported(); | ||
} | ||
}, { | ||
key: "getWorkerFarm", | ||
value: function getWorkerFarm() { | ||
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
WorkerFarm._workerFarm = WorkerFarm._workerFarm || new WorkerFarm({}); | ||
WorkerFarm._workerFarm.setProps(props); | ||
return WorkerFarm._workerFarm; | ||
} | ||
}]); | ||
return WorkerFarm; | ||
}(); | ||
return workerPool; | ||
} | ||
_getWorkerPoolProps() { | ||
return { | ||
maxConcurrency: this.props.maxConcurrency, | ||
maxMobileConcurrency: this.props.maxMobileConcurrency, | ||
reuseWorkers: this.props.reuseWorkers, | ||
onDebug: this.props.onDebug | ||
}; | ||
} | ||
} | ||
exports.default = WorkerFarm; | ||
(0, _defineProperty2.default)(WorkerFarm, "_workerFarm", void 0); | ||
//# sourceMappingURL=worker-farm.js.map |
@@ -8,10 +8,6 @@ "use strict"; | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _assert = require("../env-utils/assert"); | ||
var WorkerJob = function () { | ||
function WorkerJob(jobName, workerThread) { | ||
var _this = this; | ||
(0, _classCallCheck2.default)(this, WorkerJob); | ||
class WorkerJob { | ||
constructor(jobName, workerThread) { | ||
(0, _defineProperty2.default)(this, "name", void 0); | ||
@@ -21,38 +17,30 @@ (0, _defineProperty2.default)(this, "workerThread", void 0); | ||
(0, _defineProperty2.default)(this, "result", void 0); | ||
(0, _defineProperty2.default)(this, "_resolve", function () {}); | ||
(0, _defineProperty2.default)(this, "_reject", function () {}); | ||
(0, _defineProperty2.default)(this, "_resolve", () => {}); | ||
(0, _defineProperty2.default)(this, "_reject", () => {}); | ||
this.name = jobName; | ||
this.workerThread = workerThread; | ||
this.result = new Promise(function (resolve, reject) { | ||
_this._resolve = resolve; | ||
_this._reject = reject; | ||
this.result = new Promise((resolve, reject) => { | ||
this._resolve = resolve; | ||
this._reject = reject; | ||
}); | ||
} | ||
(0, _createClass2.default)(WorkerJob, [{ | ||
key: "postMessage", | ||
value: function postMessage(type, payload) { | ||
this.workerThread.postMessage({ | ||
source: 'loaders.gl', | ||
type: type, | ||
payload: payload | ||
}); | ||
} | ||
}, { | ||
key: "done", | ||
value: function done(value) { | ||
(0, _assert.assert)(this.isRunning); | ||
this.isRunning = false; | ||
this._resolve(value); | ||
} | ||
}, { | ||
key: "error", | ||
value: function error(_error) { | ||
(0, _assert.assert)(this.isRunning); | ||
this.isRunning = false; | ||
this._reject(_error); | ||
} | ||
}]); | ||
return WorkerJob; | ||
}(); | ||
postMessage(type, payload) { | ||
this.workerThread.postMessage({ | ||
source: 'loaders.gl', | ||
type, | ||
payload | ||
}); | ||
} | ||
done(value) { | ||
(0, _assert.assert)(this.isRunning); | ||
this.isRunning = false; | ||
this._resolve(value); | ||
} | ||
error(error) { | ||
(0, _assert.assert)(this.isRunning); | ||
this.isRunning = false; | ||
this._reject(error); | ||
} | ||
} | ||
exports.default = WorkerJob; | ||
//# sourceMappingURL=worker-job.js.map |
@@ -8,6 +8,2 @@ "use strict"; | ||
exports.default = void 0; | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
@@ -17,7 +13,7 @@ var _globals = require("../env-utils/globals"); | ||
var _workerJob = _interopRequireDefault(require("./worker-job")); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } | ||
var WorkerPool = function () { | ||
function WorkerPool(props) { | ||
(0, _classCallCheck2.default)(this, WorkerPool); | ||
class WorkerPool { | ||
static isSupported() { | ||
return _workerThread.default.isSupported(); | ||
} | ||
constructor(props) { | ||
(0, _defineProperty2.default)(this, "name", 'unnamed'); | ||
@@ -28,3 +24,3 @@ (0, _defineProperty2.default)(this, "source", void 0); | ||
(0, _defineProperty2.default)(this, "maxMobileConcurrency", 1); | ||
(0, _defineProperty2.default)(this, "onDebug", function () {}); | ||
(0, _defineProperty2.default)(this, "onDebug", () => {}); | ||
(0, _defineProperty2.default)(this, "reuseWorkers", true); | ||
@@ -40,176 +36,101 @@ (0, _defineProperty2.default)(this, "props", {}); | ||
} | ||
(0, _createClass2.default)(WorkerPool, [{ | ||
key: "destroy", | ||
value: function destroy() { | ||
this.idleQueue.forEach(function (worker) { | ||
return worker.destroy(); | ||
destroy() { | ||
this.idleQueue.forEach(worker => worker.destroy()); | ||
this.isDestroyed = true; | ||
} | ||
setProps(props) { | ||
this.props = { | ||
...this.props, | ||
...props | ||
}; | ||
if (props.name !== undefined) { | ||
this.name = props.name; | ||
} | ||
if (props.maxConcurrency !== undefined) { | ||
this.maxConcurrency = props.maxConcurrency; | ||
} | ||
if (props.maxMobileConcurrency !== undefined) { | ||
this.maxMobileConcurrency = props.maxMobileConcurrency; | ||
} | ||
if (props.reuseWorkers !== undefined) { | ||
this.reuseWorkers = props.reuseWorkers; | ||
} | ||
if (props.onDebug !== undefined) { | ||
this.onDebug = props.onDebug; | ||
} | ||
} | ||
async startJob(name) { | ||
let onMessage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (job, type, data) => job.done(data); | ||
let onError = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (job, error) => job.error(error); | ||
const startPromise = new Promise(onStart => { | ||
this.jobQueue.push({ | ||
name, | ||
onMessage, | ||
onError, | ||
onStart | ||
}); | ||
this.isDestroyed = true; | ||
return this; | ||
}); | ||
this._startQueuedJob(); | ||
return await startPromise; | ||
} | ||
async _startQueuedJob() { | ||
if (!this.jobQueue.length) { | ||
return; | ||
} | ||
}, { | ||
key: "setProps", | ||
value: function setProps(props) { | ||
this.props = _objectSpread(_objectSpread({}, this.props), props); | ||
if (props.name !== undefined) { | ||
this.name = props.name; | ||
} | ||
if (props.maxConcurrency !== undefined) { | ||
this.maxConcurrency = props.maxConcurrency; | ||
} | ||
if (props.maxMobileConcurrency !== undefined) { | ||
this.maxMobileConcurrency = props.maxMobileConcurrency; | ||
} | ||
if (props.reuseWorkers !== undefined) { | ||
this.reuseWorkers = props.reuseWorkers; | ||
} | ||
if (props.onDebug !== undefined) { | ||
this.onDebug = props.onDebug; | ||
} | ||
const workerThread = this._getAvailableWorker(); | ||
if (!workerThread) { | ||
return; | ||
} | ||
}, { | ||
key: "startJob", | ||
value: function () { | ||
var _startJob = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(name) { | ||
var _this = this; | ||
var onMessage, | ||
onError, | ||
startPromise, | ||
_args = arguments; | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
onMessage = _args.length > 1 && _args[1] !== undefined ? _args[1] : function (job, type, data) { | ||
return job.done(data); | ||
}; | ||
onError = _args.length > 2 && _args[2] !== undefined ? _args[2] : function (job, error) { | ||
return job.error(error); | ||
}; | ||
startPromise = new Promise(function (onStart) { | ||
_this.jobQueue.push({ | ||
name: name, | ||
onMessage: onMessage, | ||
onError: onError, | ||
onStart: onStart | ||
}); | ||
return _this; | ||
}); | ||
this._startQueuedJob(); | ||
_context.next = 6; | ||
return startPromise; | ||
case 6: | ||
return _context.abrupt("return", _context.sent); | ||
case 7: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, this); | ||
})); | ||
function startJob(_x) { | ||
return _startJob.apply(this, arguments); | ||
const queuedJob = this.jobQueue.shift(); | ||
if (queuedJob) { | ||
this.onDebug({ | ||
message: 'Starting job', | ||
name: queuedJob.name, | ||
workerThread, | ||
backlog: this.jobQueue.length | ||
}); | ||
const job = new _workerJob.default(queuedJob.name, workerThread); | ||
workerThread.onMessage = data => queuedJob.onMessage(job, data.type, data.payload); | ||
workerThread.onError = error => queuedJob.onError(job, error); | ||
queuedJob.onStart(job); | ||
try { | ||
await job.result; | ||
} finally { | ||
this.returnWorkerToQueue(workerThread); | ||
} | ||
return startJob; | ||
}() | ||
}, { | ||
key: "_startQueuedJob", | ||
value: function () { | ||
var _startQueuedJob2 = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee2() { | ||
var workerThread, queuedJob, _job; | ||
return _regenerator.default.wrap(function _callee2$(_context2) { | ||
while (1) switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (this.jobQueue.length) { | ||
_context2.next = 2; | ||
break; | ||
} | ||
return _context2.abrupt("return"); | ||
case 2: | ||
workerThread = this._getAvailableWorker(); | ||
if (workerThread) { | ||
_context2.next = 5; | ||
break; | ||
} | ||
return _context2.abrupt("return"); | ||
case 5: | ||
queuedJob = this.jobQueue.shift(); | ||
if (!queuedJob) { | ||
_context2.next = 18; | ||
break; | ||
} | ||
this.onDebug({ | ||
message: 'Starting job', | ||
name: queuedJob.name, | ||
workerThread: workerThread, | ||
backlog: this.jobQueue.length | ||
}); | ||
_job = new _workerJob.default(queuedJob.name, workerThread); | ||
workerThread.onMessage = function (data) { | ||
return queuedJob.onMessage(_job, data.type, data.payload); | ||
}; | ||
workerThread.onError = function (error) { | ||
return queuedJob.onError(_job, error); | ||
}; | ||
queuedJob.onStart(_job); | ||
_context2.prev = 12; | ||
_context2.next = 15; | ||
return _job.result; | ||
case 15: | ||
_context2.prev = 15; | ||
this.returnWorkerToQueue(workerThread); | ||
return _context2.finish(15); | ||
case 18: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
}, _callee2, this, [[12,, 15, 18]]); | ||
})); | ||
function _startQueuedJob() { | ||
return _startQueuedJob2.apply(this, arguments); | ||
} | ||
return _startQueuedJob; | ||
}() | ||
}, { | ||
key: "returnWorkerToQueue", | ||
value: function returnWorkerToQueue(worker) { | ||
var shouldDestroyWorker = this.isDestroyed || !this.reuseWorkers || this.count > this._getMaxConcurrency(); | ||
if (shouldDestroyWorker) { | ||
worker.destroy(); | ||
this.count--; | ||
} else { | ||
this.idleQueue.push(worker); | ||
} | ||
if (!this.isDestroyed) { | ||
this._startQueuedJob(); | ||
} | ||
} | ||
}, { | ||
key: "_getAvailableWorker", | ||
value: function _getAvailableWorker() { | ||
if (this.idleQueue.length > 0) { | ||
return this.idleQueue.shift() || null; | ||
} | ||
if (this.count < this._getMaxConcurrency()) { | ||
this.count++; | ||
var name = "".concat(this.name.toLowerCase(), " (#").concat(this.count, " of ").concat(this.maxConcurrency, ")"); | ||
return new _workerThread.default({ | ||
name: name, | ||
source: this.source, | ||
url: this.url | ||
}); | ||
} | ||
return null; | ||
} | ||
returnWorkerToQueue(worker) { | ||
const shouldDestroyWorker = this.isDestroyed || !this.reuseWorkers || this.count > this._getMaxConcurrency(); | ||
if (shouldDestroyWorker) { | ||
worker.destroy(); | ||
this.count--; | ||
} else { | ||
this.idleQueue.push(worker); | ||
} | ||
}, { | ||
key: "_getMaxConcurrency", | ||
value: function _getMaxConcurrency() { | ||
return _globals.isMobile ? this.maxMobileConcurrency : this.maxConcurrency; | ||
if (!this.isDestroyed) { | ||
this._startQueuedJob(); | ||
} | ||
}], [{ | ||
key: "isSupported", | ||
value: function isSupported() { | ||
return _workerThread.default.isSupported(); | ||
} | ||
_getAvailableWorker() { | ||
if (this.idleQueue.length > 0) { | ||
return this.idleQueue.shift() || null; | ||
} | ||
}]); | ||
return WorkerPool; | ||
}(); | ||
if (this.count < this._getMaxConcurrency()) { | ||
this.count++; | ||
const name = "".concat(this.name.toLowerCase(), " (#").concat(this.count, " of ").concat(this.maxConcurrency, ")"); | ||
return new _workerThread.default({ | ||
name, | ||
source: this.source, | ||
url: this.url | ||
}); | ||
} | ||
return null; | ||
} | ||
_getMaxConcurrency() { | ||
return _globals.isMobile ? this.maxMobileConcurrency : this.maxConcurrency; | ||
} | ||
} | ||
exports.default = WorkerPool; | ||
//# sourceMappingURL=worker-pool.js.map |
@@ -8,4 +8,2 @@ "use strict"; | ||
exports.default = void 0; | ||
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); | ||
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
@@ -17,6 +15,8 @@ var _worker_threads = require("../node/worker_threads"); | ||
var _getTransferList = require("../worker-utils/get-transfer-list"); | ||
var NOOP = function NOOP() {}; | ||
var WorkerThread = function () { | ||
function WorkerThread(props) { | ||
(0, _classCallCheck2.default)(this, WorkerThread); | ||
const NOOP = () => {}; | ||
class WorkerThread { | ||
static isSupported() { | ||
return typeof Worker !== 'undefined' && _globals.isBrowser || typeof _worker_threads.NodeWorker !== 'undefined' && !_globals.isBrowser; | ||
} | ||
constructor(props) { | ||
(0, _defineProperty2.default)(this, "name", void 0); | ||
@@ -30,5 +30,7 @@ (0, _defineProperty2.default)(this, "source", void 0); | ||
(0, _defineProperty2.default)(this, "_loadableURL", ''); | ||
var name = props.name, | ||
source = props.source, | ||
url = props.url; | ||
const { | ||
name, | ||
source, | ||
url | ||
} = props; | ||
(0, _assert.assert)(source || url); | ||
@@ -39,102 +41,77 @@ this.name = name; | ||
this.onMessage = NOOP; | ||
this.onError = function (error) { | ||
return console.log(error); | ||
}; | ||
this.onError = error => console.log(error); | ||
this.worker = _globals.isBrowser ? this._createBrowserWorker() : this._createNodeWorker(); | ||
} | ||
(0, _createClass2.default)(WorkerThread, [{ | ||
key: "destroy", | ||
value: function destroy() { | ||
this.onMessage = NOOP; | ||
this.onError = NOOP; | ||
this.worker.terminate(); | ||
this.terminated = true; | ||
destroy() { | ||
this.onMessage = NOOP; | ||
this.onError = NOOP; | ||
this.worker.terminate(); | ||
this.terminated = true; | ||
} | ||
get isRunning() { | ||
return Boolean(this.onMessage); | ||
} | ||
postMessage(data, transferList) { | ||
transferList = transferList || (0, _getTransferList.getTransferList)(data); | ||
this.worker.postMessage(data, transferList); | ||
} | ||
_getErrorFromErrorEvent(event) { | ||
let message = 'Failed to load '; | ||
message += "worker ".concat(this.name, " from ").concat(this.url, ". "); | ||
if (event.message) { | ||
message += "".concat(event.message, " in "); | ||
} | ||
}, { | ||
key: "isRunning", | ||
get: function get() { | ||
return Boolean(this.onMessage); | ||
if (event.lineno) { | ||
message += ":".concat(event.lineno, ":").concat(event.colno); | ||
} | ||
}, { | ||
key: "postMessage", | ||
value: function postMessage(data, transferList) { | ||
transferList = transferList || (0, _getTransferList.getTransferList)(data); | ||
this.worker.postMessage(data, transferList); | ||
} | ||
}, { | ||
key: "_getErrorFromErrorEvent", | ||
value: function _getErrorFromErrorEvent(event) { | ||
var message = 'Failed to load '; | ||
message += "worker ".concat(this.name, " from ").concat(this.url, ". "); | ||
if (event.message) { | ||
message += "".concat(event.message, " in "); | ||
} | ||
if (event.lineno) { | ||
message += ":".concat(event.lineno, ":").concat(event.colno); | ||
} | ||
return new Error(message); | ||
} | ||
}, { | ||
key: "_createBrowserWorker", | ||
value: function _createBrowserWorker() { | ||
var _this = this; | ||
this._loadableURL = (0, _getLoadableWorkerUrl.getLoadableWorkerURL)({ | ||
source: this.source, | ||
url: this.url | ||
}); | ||
var worker = new Worker(this._loadableURL, { | ||
name: this.name | ||
}); | ||
worker.onmessage = function (event) { | ||
if (!event.data) { | ||
_this.onError(new Error('No data received')); | ||
} else { | ||
_this.onMessage(event.data); | ||
} | ||
}; | ||
worker.onerror = function (error) { | ||
_this.onError(_this._getErrorFromErrorEvent(error)); | ||
_this.terminated = true; | ||
}; | ||
worker.onmessageerror = function (event) { | ||
return console.error(event); | ||
}; | ||
return worker; | ||
} | ||
}, { | ||
key: "_createNodeWorker", | ||
value: function _createNodeWorker() { | ||
var _this2 = this; | ||
var worker; | ||
if (this.url) { | ||
var absolute = this.url.includes(':/') || this.url.startsWith('/'); | ||
var url = absolute ? this.url : "./".concat(this.url); | ||
worker = new _worker_threads.NodeWorker(url, { | ||
eval: false | ||
}); | ||
} else if (this.source) { | ||
worker = new _worker_threads.NodeWorker(this.source, { | ||
eval: true | ||
}); | ||
return new Error(message); | ||
} | ||
_createBrowserWorker() { | ||
this._loadableURL = (0, _getLoadableWorkerUrl.getLoadableWorkerURL)({ | ||
source: this.source, | ||
url: this.url | ||
}); | ||
const worker = new Worker(this._loadableURL, { | ||
name: this.name | ||
}); | ||
worker.onmessage = event => { | ||
if (!event.data) { | ||
this.onError(new Error('No data received')); | ||
} else { | ||
throw new Error('no worker'); | ||
this.onMessage(event.data); | ||
} | ||
worker.on('message', function (data) { | ||
_this2.onMessage(data); | ||
}; | ||
worker.onerror = error => { | ||
this.onError(this._getErrorFromErrorEvent(error)); | ||
this.terminated = true; | ||
}; | ||
worker.onmessageerror = event => console.error(event); | ||
return worker; | ||
} | ||
_createNodeWorker() { | ||
let worker; | ||
if (this.url) { | ||
const absolute = this.url.includes(':/') || this.url.startsWith('/'); | ||
const url = absolute ? this.url : "./".concat(this.url); | ||
worker = new _worker_threads.NodeWorker(url, { | ||
eval: false | ||
}); | ||
worker.on('error', function (error) { | ||
_this2.onError(error); | ||
} else if (this.source) { | ||
worker = new _worker_threads.NodeWorker(this.source, { | ||
eval: true | ||
}); | ||
worker.on('exit', function (code) {}); | ||
return worker; | ||
} else { | ||
throw new Error('no worker'); | ||
} | ||
}], [{ | ||
key: "isSupported", | ||
value: function isSupported() { | ||
return typeof Worker !== 'undefined' && _globals.isBrowser || typeof _worker_threads.NodeWorker !== 'undefined' && !_globals.isBrowser; | ||
} | ||
}]); | ||
return WorkerThread; | ||
}(); | ||
worker.on('message', data => { | ||
this.onMessage(data); | ||
}); | ||
worker.on('error', error => { | ||
this.onError(error); | ||
}); | ||
worker.on('exit', code => {}); | ||
return worker; | ||
} | ||
} | ||
exports.default = WorkerThread; | ||
//# sourceMappingURL=worker-thread.js.map |
@@ -8,6 +8,6 @@ "use strict"; | ||
var _assert = require("../env-utils/assert"); | ||
var workerURLCache = new Map(); | ||
const workerURLCache = new Map(); | ||
function getLoadableWorkerURL(props) { | ||
(0, _assert.assert)(props.source && !props.url || !props.source && props.url); | ||
var workerURL = workerURLCache.get(props.source || props.url); | ||
let workerURL = workerURLCache.get(props.source || props.url); | ||
if (!workerURL) { | ||
@@ -30,7 +30,7 @@ if (props.url) { | ||
} | ||
var workerSource = buildScriptSource(url); | ||
const workerSource = buildScriptSource(url); | ||
return getLoadableWorkerURLFromSource(workerSource); | ||
} | ||
function getLoadableWorkerURLFromSource(workerSource) { | ||
var blob = new Blob([workerSource], { | ||
const blob = new Blob([workerSource], { | ||
type: 'application/javascript' | ||
@@ -37,0 +37,0 @@ }); |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,7 +8,6 @@ value: true | ||
exports.getTransferListForWriter = getTransferListForWriter; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
function getTransferList(object) { | ||
var recursive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
var transfers = arguments.length > 2 ? arguments[2] : undefined; | ||
var transfersSet = transfers || new Set(); | ||
let recursive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
let transfers = arguments.length > 2 ? arguments[2] : undefined; | ||
const transfersSet = transfers || new Set(); | ||
if (!object) {} else if (isTransferable(object)) { | ||
@@ -19,4 +17,4 @@ transfersSet.add(object); | ||
transfersSet.add(object.buffer); | ||
} else if (ArrayBuffer.isView(object)) {} else if (recursive && (0, _typeof2.default)(object) === 'object') { | ||
for (var key in object) { | ||
} else if (ArrayBuffer.isView(object)) {} else if (recursive && typeof object === 'object') { | ||
for (const key in object) { | ||
getTransferList(object[key], recursive, transfersSet); | ||
@@ -49,5 +47,5 @@ } | ||
} | ||
var clone = Object.assign({}, object); | ||
Object.keys(clone).forEach(function (key) { | ||
if ((0, _typeof2.default)(object[key]) === 'object' && !ArrayBuffer.isView(object[key]) && !(object[key] instanceof Array)) { | ||
const clone = Object.assign({}, object); | ||
Object.keys(clone).forEach(key => { | ||
if (typeof object[key] === 'object' && !ArrayBuffer.isView(object[key]) && !(object[key] instanceof Array)) { | ||
clone[key] = getTransferListForWriter(object[key]); | ||
@@ -54,0 +52,0 @@ } else if (typeof clone[key] === 'function' || clone[key] instanceof RegExp) { |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,3 +7,2 @@ value: true | ||
exports.removeNontransferableOptions = removeNontransferableOptions; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
function removeNontransferableOptions(object) { | ||
@@ -14,5 +12,5 @@ if (object === null) { | ||
} | ||
var clone = Object.assign({}, object); | ||
Object.keys(clone).forEach(function (key) { | ||
if ((0, _typeof2.default)(object[key]) === 'object' && !ArrayBuffer.isView(object[key])) { | ||
const clone = Object.assign({}, object); | ||
Object.keys(clone).forEach(key => { | ||
if (typeof object[key] === 'object' && !ArrayBuffer.isView(object[key])) { | ||
clone[key] = removeNontransferableOptions(object[key]); | ||
@@ -19,0 +17,0 @@ } else if (typeof clone[key] === 'function' || clone[key] instanceof RegExp) { |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); | ||
var _createWorker = require("../lib/worker-api/create-worker"); | ||
(0, _createWorker.createWorker)(function () { | ||
var _ref = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(data) { | ||
return _regenerator.default.wrap(function _callee$(_context) { | ||
while (1) switch (_context.prev = _context.next) { | ||
case 0: | ||
return _context.abrupt("return", data); | ||
case 1: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee); | ||
})); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}()); | ||
(0, _createWorker.createWorker)(async data => { | ||
return data; | ||
}); | ||
//# sourceMappingURL=null-worker.js.map |
const DEFAULT_VERSION = 'latest'; | ||
export const VERSION = typeof "3.4.14" !== 'undefined' ? "3.4.14" : DEFAULT_VERSION; | ||
if (typeof "3.4.14" === 'undefined') { | ||
export const VERSION = typeof "3.4.15" !== 'undefined' ? "3.4.15" : DEFAULT_VERSION; | ||
if (typeof "3.4.15" === 'undefined') { | ||
console.error('loaders.gl: The __VERSION__ variable is not injected using babel plugin. Latest unstable workers would be fetched from the CDN.'); | ||
} | ||
//# sourceMappingURL=version.js.map |
@@ -6,3 +6,3 @@ import { global, isBrowser, isWorker } from '../env-utils/globals'; | ||
const LATEST = 'latest'; | ||
const VERSION = typeof "3.4.14" !== 'undefined' ? "3.4.14" : LATEST; | ||
const VERSION = typeof "3.4.15" !== 'undefined' ? "3.4.15" : LATEST; | ||
const loadLibraryPromises = {}; | ||
@@ -9,0 +9,0 @@ export async function loadLibrary(libraryUrl) { |
import { assert } from '../env-utils/assert'; | ||
import { VERSION as __VERSION__ } from '../env-utils/version'; | ||
const NPM_TAG = 'latest'; | ||
const VERSION = typeof "3.4.14" !== 'undefined' ? "3.4.14" : NPM_TAG; | ||
const VERSION = typeof "3.4.15" !== 'undefined' ? "3.4.15" : NPM_TAG; | ||
export function getWorkerName(worker) { | ||
@@ -6,0 +6,0 @@ const warning = worker.version !== VERSION ? " (worker-utils@".concat(VERSION, ")") : ''; |
{ | ||
"name": "@loaders.gl/worker-utils", | ||
"version": "3.4.14", | ||
"version": "3.4.15", | ||
"description": "Utilities for running tasks on worker threads", | ||
@@ -51,3 +51,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "dffa197c6ae79bac5277d5e8a132f4cd274e74e5" | ||
"gitHead": "19e941d5805568e449ef9092490d6568a4853298" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
421160
4948