1 line
24 KiB
JavaScript
1 line
24 KiB
JavaScript
|
(()=>{"use strict";var e={914:e=>{e.exports=(e,t=process.argv)=>{const r=e.startsWith("-")?"":e.length===1?"-":"--";const i=t.indexOf(r+e);const s=t.indexOf("--");return i!==-1&&(s===-1||i<s)}},460:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t["default"]=void 0;var i=_interopRequireDefault(r(552));var s=r(582);function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _defineProperty(e,t,r){if(t in e){Object.defineProperty(e,t,{value:r,enumerable:true,configurable:true,writable:true})}else{e[t]=r}return e}class Farm{constructor(e,t,r={}){var s,o;_defineProperty(this,"_computeWorkerKey",void 0);_defineProperty(this,"_workerSchedulingPolicy",void 0);_defineProperty(this,"_cacheKeys",Object.create(null));_defineProperty(this,"_locks",[]);_defineProperty(this,"_offset",0);_defineProperty(this,"_taskQueue",void 0);this._numOfWorkers=e;this._callback=t;this._computeWorkerKey=r.computeWorkerKey;this._workerSchedulingPolicy=(s=r.workerSchedulingPolicy)!==null&&s!==void 0?s:"round-robin";this._taskQueue=(o=r.taskQueue)!==null&&o!==void 0?o:new i.default}doWork(e,...t){const r=new Set;const addCustomMessageListener=e=>{r.add(e);return()=>{r.delete(e)}};const onCustomMessage=e=>{r.forEach((t=>t(e)))};const i=new Promise(((t,i,o)=>{const n=this._computeWorkerKey;const u=[s.CHILD_MESSAGE_CALL,false,e,t];let _=null;let l=null;if(n){l=n.call(this,e,...t);_=l==null?null:this._cacheKeys[l]}const onStart=e=>{if(l!=null){this._cacheKeys[l]=e}};const onEnd=(e,t)=>{r.clear();if(e){o(e)}else{i(t)}};const a={onCustomMessage:onCustomMessage,onEnd:onEnd,onStart:onStart,request:u};if(_){this._taskQueue.enqueue(a,_.getWorkerId());this._process(_.getWorkerId())}else{this._push(a)}}).bind(null,t));i.UNSTABLE_onCustomMessage=addCustomMessageListener;return i}_process(e){if(this._isLocked(e)){return this}const t=this._taskQueue.dequeue(e);if(!t){return this}if(t.request[1]){throw new Error("Queue implementation returned processed task")}const r=t.onEnd;const onEnd=(t,i)=>{r(t,i);this._unlock(e);this._process(e)};t.request[1]=true;this._lock(e);this._callback(e,t.request,t.onStart,onEnd,t.onCustomMessage);return this}_push(e){this._taskQueue.enqueue(e);const t=this._getNextWorkerOffset();for(let r=0;r<this._numOfWorkers;r++){this._process((t+r)%this._numOfWorkers);if(e.request[1]){break}}return this}_getNextWorkerOffset(){switch(this._workerSchedulingPolicy){case"in-order":return 0;case"round-robin":return this._offset++}}_lock(e){this._locks[e]=true}_unlock(e){this._locks[e]=false}_isLocked(e){return this._locks[e]}}t["default"]=Farm},552:(e,t)=>{Object.defineProperty(t,"__esModule",{value:true});t["default"]=void 0;function _defineProperty(e,t,r){if(t in e){Object.defineProperty(e,t,{value:r,enumerable:true,configurable:true,writable:true})}else{e[t]=r}return e}class FifoQueue{constructor(){_defineProperty(this,"_workerQueues",[]);_defineProperty(this,"_sharedQueue",new InternalQueue)}enqueue(e,t){if(t==null){this._sharedQueue.enqueue(e);return}let r=this._workerQueues[t];if(r==null){r=this._workerQueues[t]=new InternalQueue}const i=this._sharedQueue.peekLast();const s={previousSharedTask:i,task:e};r.enqueue(s)}dequeue(e){var t,r,i;const s=(t=this._workerQueues[e])===null||t===void 0?void 0:t.peek();const o=(r=s===null||s===void 0?void 0:(i=s.previousSharedTask)===null||i===void 0?void 0:i.request[1])!==null&&r!==void 0?r:true;if(s!=null&&o){var n,u,_;return(n=(u=this._workerQueues[e])===null||u===void 0?void 0:(_=u.dequeue())===null||_===void 0?void 0:_.task)!==null&&n!==void 0?n:null}return this._sharedQueue.dequeue()}}t["default"]=FifoQueue;class InternalQueue{constructor(){_defineProperty(this,"_head",null);_defineProperty(this,"_last",null)}enqueue(e){const t={next:null,value:e};if(this._last==null){this._head=t}else{this._last.next=t}this._last=t}dequeue(){if(this._head==null){return null}const e=this._head;this._head=e.next;if(this._head==null){this._last=null}return e.value}peek(){var e,t;return(e=(t=this._head)===null||t===void 0?void 0:t.value)!==null&&e!==void 0?e:null}peekLast(){var e,t;return(e=(t=
|