UNPKG

@loaders.gl/core

Version:

Framework-independent loaders for 3D graphics formats

92 lines (80 loc) 2.74 kB
import _regeneratorRuntime from "@babel/runtime/regenerator"; import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import WorkerPool from './worker-pool'; var DEFAULT_MAX_CONCURRENCY = 5; var WorkerFarm = function () { function WorkerFarm(_ref) { var _ref$maxConcurrency = _ref.maxConcurrency, maxConcurrency = _ref$maxConcurrency === void 0 ? DEFAULT_MAX_CONCURRENCY : _ref$maxConcurrency, onMessage = _ref.onMessage, _ref$onDebug = _ref.onDebug, onDebug = _ref$onDebug === void 0 ? function () {} : _ref$onDebug; _classCallCheck(this, WorkerFarm); this.maxConcurrency = maxConcurrency; this.onMessage = onMessage; this.onDebug = onDebug; this.workerPools = new Map(); } _createClass(WorkerFarm, [{ key: "setProps", value: function setProps(props) { if ('maxConcurrency' in props) { this.maxConcurrency = props.maxConcurrency; } if ('onDebug' in props) { this.onDebug = props.onDebug; } } }, { key: "destroy", value: function destroy() { this.workerPools.forEach(function (workerPool) { return workerPool.destroy(); }); } }, { key: "process", value: function () { var _process = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(workerSource, workerName, data) { var workerPool; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: workerPool = this._getWorkerPool(workerSource, workerName); return _context.abrupt("return", workerPool.process(data)); case 2: case "end": return _context.stop(); } } }, _callee, this); })); function process(_x, _x2, _x3) { return _process.apply(this, arguments); } return process; }() }, { key: "_getWorkerPool", value: function _getWorkerPool(workerSource, workerName) { var workerPool = this.workerPools.get(workerName); if (!workerPool) { workerPool = new WorkerPool({ source: workerSource, name: workerName, onMessage: this.onMessage, maxConcurrency: this.maxConcurrency, onDebug: this.onDebug }); this.workerPools.set(workerName, workerPool); } return workerPool; } }]); return WorkerFarm; }(); export { WorkerFarm as default }; //# sourceMappingURL=worker-farm.js.map