diff --git a/.travis.yml b/.travis.yml index 7909e5c..2a50422 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,4 +6,5 @@ script: - npm install - npm run test-coverage -after_success: 'npm run coveralls' \ No newline at end of file +after_success: + - npm run coveralls \ No newline at end of file diff --git a/dist/operationkit.min.js b/dist/operationkit.min.js index 2105f1f..22a982d 100644 --- a/dist/operationkit.min.js +++ b/dist/operationkit.min.js @@ -1,2 +1,2 @@ -!function(e){var t={};function i(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)i.d(n,r,function(t){return e[t]}.bind(null,r));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=4)}([function(e,t,i){const n=i(5),r=i(6),{OperationEvent:s}=i(2),{QueuePriority:o}=i(1),{copyArray:u}=i(9);e.exports={Operation:class{constructor(e){e||(e=r()),this.id=e,this.ee=new n,this._dependencies=[],this.completionCallback=null,this.map={},this.isExecuting=!1,this._done=!1,this._isInQueue=!1,this._canStart=!1,this._cancelled=!1,this.error=!0,this.name=null,this.promise=null,this.runPromise=null,this._queuePriority=o.normal,this._resolve=null,this._reject=null}done(){this._done=!0,this.completionCallback&&this.completionCallback(this),this.ee.emit(s.DONE,this),console.log(`done: ${this.id}`),this._resolve&&this._resolve(this.result)}isDone(){return this._done}get isFinished(){return this._done}cancel(){this._cancelled=!0,Promise.resolve(this.promise),this.ee.emit(s.CANCEL,this),this._resolve&&this._resolve()}get isCancelled(){return this._cancelled}set isInQueue(e){this._isInQueue=e}get isInQueue(){return this._isInQueue}set queuePriority(e){this.isExecuting||this.isCancelled||this.isFinished||o.isValid(e)&&(this._queuePriority=e)}get queuePriority(){return this._queuePriority}set dependencies(e){this.isExecuting||this.isCancelled||this.isFinished||(this._dependencies=e)}get dependencies(){return this.isExecuting||this.isCancelled||this.isFinished?u(this._dependencies):this._dependencies}on(e,t){this.ee.on(e,t)}off(e,t){this.ee.off(e,t)}addDependency(e){this._dependencies.push(e)}removeDependency(e){this._dependencies=this._dependencies.filter(t=>t.id!==e.id)}async run(){throw new Error("run function must be implemented")}main(){this.isExecuting=!0,this.ee.emit(s.START,this),this.runPromise=this.run().then(e=>{this.result=e,this.done()}).catch(e=>{this.isExecuting=!1,this.error=!0,this.ee.emit(s.ERROR,{err:e,operation:this}),this.ee.emit(s.DONE,this),this._reject&&this._reject()})}start(){return this.isExecuting||this.isCancelled||this.isFinished?this.promise:(this.promise&&!this._canStart?this._preProcessStart():this.promise&&this._canStart?this._isInQueue?this.ee.emit(s.READY,this):this.main():this.promise=new Promise((e,t)=>{this._resolve=e,this._reject=t,this._preProcessStart()}),this.promise)}_preProcessStart(){this._createMap(),this._canStart&&(this._isInQueue?this.ee.emit(s.READY,this):this.main())}_createMap(){this._dependencies.length?this._dependencies.forEach(e=>{this.map[e.id]=!0,e.on(s.DONE,this._onDependantOperationDone.bind(this)),e.start()}):this._canStart=!0}_onDependantOperationDone(e){delete this.map[e.id],this._tryStart()}_tryStart(){this.isExecuting||this.isCancelled||this.isFinished||this._isEmpty(this.map)&&(this._canStart=!0,this.isInQueue?this.ee.emit(s.READY,this):this.start())}_isEmpty(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return!0}}}},function(e,t){const i={veryLow:0,low:1,normal:2,high:3,veryHigh:4,isValid:e=>e>=i.veryLow&&e<=i.veryHigh};e.exports={QueuePriority:i}},function(e,t){e.exports={OperationEvent:{START:"start",READY:"ready",DONE:"done",CANCEL:"cancel",ERROR:"e"}}},function(e,t,i){const{CircularOperationChecker:n}=i(10),{QueuePriority:r}=i(1);e.exports={OperationQueue:class{constructor(){this.time={},this.map={},this.operations=[],this.resolve=null,this.completionCallback=null,this.maximumConcurentOperations=10,this.readyQueueMap={},this.readyQueue=[],this.runningQueueMap={},this.runningQueue=[],this.queues={[r.veryHigh]:[],[r.high]:[],[r.normal]:[],[r.low]:[],[r.veryLow]:[]},this._isDone=!1}get totalTime(){return Math.abs((this.time.start.getTime()-this.time.end.getTime())/1e3)}get isExecuting(){return!this._isEmpty(this.map)}done(){this._isDone||(this.time.end=new Date,this._isDone=!0,this.completionCallback&&this.completionCallback(),this.resolve())}async addOperation(e){return this.addOperations([e])}async addOperations(e){return this.operations=this.operations.concat(e),this._preProcessOperations(this.operations),this._begin()}pause(){this._paused=!0}resume(){this._paused=!1,this._checkNextOperation()}get isPaused(){return this._paused}_preProcessOperations(e){e.forEach(e=>{this.map[e.id]||(this.map[e.id]=!0,e.isInQueue=!0,e.on("start",this._onOperationStart.bind(this)),e.on("ready",this._onOperationReady.bind(this)),e.on("cancel",this._onOperationCancel.bind(this)),e.on("done",this._onOperationDone.bind(this))),this._preProcessOperations(e.dependencies)})}_begin(){return this.promise?this._startOperations():this.promise=new Promise((e,t)=>{try{new n(this.operations)}catch(e){return t(e)}this.time.start=new Date,this.resolve=e,this._startOperations()}),this.promise}_startOperations(){this.operations.forEach(e=>{this._startOperation(e)})}_startOperation(e){e.start()}_onOperationStart(e){}_onOperationReady(e){this.readyQueueMap[e.id]||(this.readyQueueMap[e.id]=!0,this.queues[e.queuePriority].push(e),this._checkNextOperation())}_onOperationDone(e){this.runningQueue=this.runningQueue.filter(t=>t.id!==e.id),delete this.map[e.id],delete this.runningQueueMap[e.id],this._isEmpty(this.map)?this.done():this._checkNextOperation()}_checkNextOperation(){if(!this._paused&&this.runningQueue.length0&&o.length>r&&!o.warned){o.warned=!0;var h=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");h.name="MaxListenersExceededWarning",h.emitter=e,h.type=t,h.count=o.length,u=h,console&&console.warn&&console.warn(u)}return e}function c(e,t,i){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:i},r=function(){for(var e=[],t=0;t0&&(o=t[0]),o instanceof Error)throw o;var u=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw u.context=o,u}var h=r[e];if(void 0===h)return!1;if("function"==typeof h)s(h,this,t);else{var a=h.length,p=f(h,a);for(i=0;i=0;s--)if(i[s]===t||i[s].listener===t){o=i[s].listener,r=s;break}if(r<0)return this;0===r?i.shift():function(e,t){for(;t+1=0;n--)this.removeListener(e,t[n]);return this},u.prototype.listeners=function(e){return l(this,e,!0)},u.prototype.rawListeners=function(e){return l(this,e,!1)},u.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):d.call(e,t)},u.prototype.listenerCount=d,u.prototype.eventNames=function(){return this._eventsCount>0?n(this._events):[]}},function(e,t,i){var n=i(7),r=i(8);e.exports=function(e,t,i){var s=t&&i||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var o=(e=e||{}).random||(e.rng||n)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t)for(var u=0;u<16;++u)t[s+u]=o[u];return t||r(o)}},function(e,t){var i="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(i){var n=new Uint8Array(16);e.exports=function(){return i(n),n}}else{var r=new Array(16);e.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),r[t]=e>>>((3&t)<<3)&255;return r}}},function(e,t){for(var i=[],n=0;n<256;++n)i[n]=(n+256).toString(16).substr(1);e.exports=function(e,t){var n=t||0,r=i;return[r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]]].join("")}},function(e,t){e.exports={copyArray:e=>e.map(e=>Object.assign(Object.create(e),e)),copyObject:e=>Object.assign(Object.create(e),e)}},function(e,t){class i extends Error{constructor(e="Circular dependency"){super(),this.message=e}}e.exports={CircularOperationChecker:class{constructor(e){this.operations=e,this._checkCircular()}_checkCircular(){this.operations.forEach(e=>{e.dependencies.forEach(t=>{let i={};i[e.id]=Object.keys(i).length,this._verifyOpMap(t,i),this._checkDependencies(t,i)})})}_checkDependencies(e,t){e.dependencies.forEach(e=>{let i=JSON.parse(JSON.stringify(t));this._verifyOpMap(e,i),this._checkDependencies(e,i)})}_verifyOpMap(e,t){void 0!==t[e.id]&&this._throwError(e,t),t[e.id]=Object.keys(t).length}_throwError(){Object.keys(map);let e={};for(let t in map)e[map[t]]=t;throw(e=Object.values(e)).push(op.id),new i(`Circular: ${e}`)}}}},function(e,t,i){const{Operation:n}=i(0);e.exports={BlockOperation:class extends n{constructor(){let e,t;const i=arguments[0];if("number"==typeof i){e=i;const n=arguments[1];"function"==typeof n&&(t=n)}else"function"==typeof i&&(t=i);super(e),this.block=t}run(){return this.block()}}}},function(e,t,i){const{Operation:n}=i(0),{OperationQueue:r}=i(3);e.exports={GroupOperation:class extends n{constructor(){super(),this.queue=new r,this.operations=[]}async run(){return await this.queue.addOperations(this.operations),this.operations.reduce((e,t)=>(e.push(t.result),e),[])}async start(){return this.dependencies=[],super.start()}addOperation(e){this.operations.push(e),this.dependencies=[]}addOperations(e){this.operations=this.operations.concat(e),this.dependencies=[]}}}}]); +!function(e){var t={};function i(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)i.d(n,r,function(t){return e[t]}.bind(null,r));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=5)}([function(e,t,i){const n=i(2),r=i(6),{OperationEvent:s}=i(3),{QueuePriority:o}=i(1),{copyArray:u}=i(9);e.exports={Operation:class{constructor(e){e||(e=r()),this.id=e,this.ee=new n,this._dependencies=[],this.completionCallback=null,this.map={},this.isExecuting=!1,this._done=!1,this._isInQueue=!1,this._canStart=!1,this._cancelled=!1,this.error=!0,this.name=null,this.promise=null,this.runPromise=null,this._queuePriority=o.normal,this._resolve=null,this._reject=null}done(){this._done=!0,this.completionCallback&&this.completionCallback(this),this.ee.emit(s.DONE,this),this._resolve&&this._resolve(this.result)}isDone(){return this._done}get isFinished(){return this._done}cancel(){this._cancelled=!0,Promise.resolve(this.promise),this.ee.emit(s.CANCEL,this),this._resolve&&this._resolve()}get isCancelled(){return this._cancelled}set isInQueue(e){this._isInQueue=e}get isInQueue(){return this._isInQueue}set queuePriority(e){this.isExecuting||this.isCancelled||this.isFinished||o.isValid(e)&&(this._queuePriority=e)}get queuePriority(){return this._queuePriority}set dependencies(e){this.isExecuting||this.isCancelled||this.isFinished||(this._dependencies=e)}get dependencies(){return this.isExecuting||this.isCancelled||this.isFinished?u(this._dependencies):this._dependencies}on(e,t){this.ee.on(e,t)}off(e,t){this.ee.off(e,t)}addDependency(e){this._dependencies.push(e)}removeDependency(e){this._dependencies=this._dependencies.filter(t=>t.id!==e.id)}async run(){throw new Error("run function must be implemented")}main(){this.isExecuting=!0,this.ee.emit(s.START,this),this.runPromise=this.run().then(e=>{this.result=e,this.done()}).catch(e=>{this.isExecuting=!1,this.error=!0,this.ee.emit(s.ERROR,{err:e,operation:this}),this.ee.emit(s.DONE,this),this._reject&&this._reject()})}start(){return this.isExecuting||this.isCancelled||this.isFinished?this.promise:(this.promise&&!this._canStart?this._preProcessStart():this.promise&&this._canStart?this._isInQueue?this.ee.emit(s.READY,this):this.main():this.promise=new Promise((e,t)=>{this._resolve=e,this._reject=t,this._preProcessStart()}),this.promise)}_preProcessStart(){this._createMap(),this._canStart&&(this._isInQueue?this.ee.emit(s.READY,this):this.main())}_createMap(){this._dependencies.length?this._dependencies.forEach(e=>{this.map[e.id]=!0,e.on(s.DONE,this._onDependantOperationDone.bind(this)),e.start()}):this._canStart=!0}_onDependantOperationDone(e){delete this.map[e.id],this._tryStart()}_tryStart(){this.isExecuting||this.isCancelled||this.isFinished||this._isEmpty(this.map)&&(this._canStart=!0,this.isInQueue?this.ee.emit(s.READY,this):this.start())}_isEmpty(e){for(var t in e)if(e.hasOwnProperty(t))return!1;return!0}}}},function(e,t){const i={veryLow:0,low:1,normal:2,high:3,veryHigh:4,isValid:e=>e>=i.veryLow&&e<=i.veryHigh};e.exports={QueuePriority:i}},function(e,t,i){"use strict";var n,r="object"==typeof Reflect?Reflect:null,s=r&&"function"==typeof r.apply?r.apply:function(e,t,i){return Function.prototype.apply.call(e,t,i)};n=r&&"function"==typeof r.ownKeys?r.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var o=Number.isNaN||function(e){return e!=e};function u(){u.init.call(this)}e.exports=u,u.EventEmitter=u,u.prototype._events=void 0,u.prototype._eventsCount=0,u.prototype._maxListeners=void 0;var h=10;function a(e){return void 0===e._maxListeners?u.defaultMaxListeners:e._maxListeners}function p(e,t,i,n){var r,s,o,u;if("function"!=typeof i)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof i);if(void 0===(s=e._events)?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,i.listener?i.listener:i),s=e._events),o=s[t]),void 0===o)o=s[t]=i,++e._eventsCount;else if("function"==typeof o?o=s[t]=n?[i,o]:[o,i]:n?o.unshift(i):o.push(i),(r=a(e))>0&&o.length>r&&!o.warned){o.warned=!0;var h=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");h.name="MaxListenersExceededWarning",h.emitter=e,h.type=t,h.count=o.length,u=h,console&&console.warn&&console.warn(u)}return e}function c(e,t,i){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:i},r=function(){for(var e=[],t=0;t0&&(o=t[0]),o instanceof Error)throw o;var u=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw u.context=o,u}var h=r[e];if(void 0===h)return!1;if("function"==typeof h)s(h,this,t);else{var a=h.length,p=f(h,a);for(i=0;i=0;s--)if(i[s]===t||i[s].listener===t){o=i[s].listener,r=s;break}if(r<0)return this;0===r?i.shift():function(e,t){for(;t+1=0;n--)this.removeListener(e,t[n]);return this},u.prototype.listeners=function(e){return l(this,e,!0)},u.prototype.rawListeners=function(e){return l(this,e,!1)},u.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):d.call(e,t)},u.prototype.listenerCount=d,u.prototype.eventNames=function(){return this._eventsCount>0?n(this._events):[]}},function(e,t){e.exports={OperationEvent:{START:"start",READY:"ready",DONE:"done",CANCEL:"cancel",ERROR:"e"}}},function(e,t,i){const n=i(2),{CircularOperationValidator:r}=i(10),{QueuePriority:s}=i(1),{QueueEvent:o}=i(11);e.exports={OperationQueue:class{constructor(){this.ee=new n,this.time={},this.map={},this.operations=[],this._processedOperations=[],this.resolve=null,this.completionCallback=null,this.maximumConcurentOperations=10,this.readyQueueMap={},this.readyQueue=[],this.runningQueueMap={},this.runningQueue=[],this.queues={[s.veryHigh]:[],[s.high]:[],[s.normal]:[],[s.low]:[],[s.veryLow]:[]},this._isDone=!1}on(e,t){this.ee.on(e,t)}off(e,t){this.ee.off(e,t)}get totalTime(){return Math.abs((this.time.start.getTime()-this.time.end.getTime())/1e3)}get isExecuting(){return!this._isEmpty(this.map)}done(){this._isDone||(this.time.end=new Date,this._isDone=!0,this.completionCallback&&this.completionCallback(),this.resolve())}addOperation(e){this.addOperations([e])}addOperations(e){this.operations=this.operations.concat(e),this._preProcessOperations(e),this._processedOperations=this._processedOperations.concat(this.operations),this._begin()}pause(){this._paused=!0}resume(){this._paused=!1,this._checkNextOperation()}get isPaused(){return this._paused}_preProcessOperations(e){e.forEach(e=>{this.map[e.id]||(this.map[e.id]=!0,e.isInQueue=!0,this._bindOperation(e)),this._preProcessOperations(e.dependencies)})}_bindOperation(e){e.on("start",this._onOperationStart.bind(this)),e.on("ready",this._onOperationReady.bind(this)),e.on("cancel",this._onOperationCancel.bind(this)),e.on("done",this._onOperationDone.bind(this))}_unbindOperation(e){e.off("start",this._onOperationStart.bind(this)),e.off("ready",this._onOperationReady.bind(this)),e.off("cancel",this._onOperationCancel.bind(this)),e.off("done",this._onOperationDone.bind(this))}_begin(){this.promise?this._startOperations():this.promise=new Promise((e,t)=>{try{new r(this._processedOperations)}catch(e){return t(e)}this.time.start=new Date,this.resolve=e,this._startOperations()})}_startOperations(){this._processedOperations.forEach(e=>{this._startOperation(e)})}_startOperation(e){e.start()}_onOperationStart(e){}_onOperationReady(e){this.readyQueueMap[e.id]||(this.readyQueueMap[e.id]=!0,this.queues[e.queuePriority].push(e),this._checkNextOperation())}_onOperationDone(e){this._unbindOperation(e),this.runningQueue=this.runningQueue.filter(t=>t.id!==e.id),delete this.map[e.id],delete this.runningQueueMap[e.id],this._isEmpty(this.map)?(this.ee.emit(o.DONE,this),this.done()):this._checkNextOperation()}_checkNextOperation(){if(!this._paused&&this.runningQueue.length>>((3&t)<<3)&255;return r}}},function(e,t){for(var i=[],n=0;n<256;++n)i[n]=(n+256).toString(16).substr(1);e.exports=function(e,t){var n=t||0,r=i;return[r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]]].join("")}},function(e,t){e.exports={copyArray:e=>e.map(e=>Object.assign(Object.create(e),e)),copyObject:e=>Object.assign(Object.create(e),e)}},function(e,t){class i extends Error{constructor(e="Circular dependency"){super(),this.message=e}}e.exports={CircularOperationValidator:class{constructor(e){this.operations=e,this._checkCircular()}_checkCircular(){this.operations.forEach(e=>{e.dependencies.forEach(t=>{let i={};i[e.id]=Object.keys(i).length,this._verifyOpMap(t,i),this._checkDependencies(t,i)})})}_checkDependencies(e,t){e.dependencies.forEach(e=>{let i=JSON.parse(JSON.stringify(t));this._verifyOpMap(e,i),this._checkDependencies(e,i)})}_verifyOpMap(e,t){void 0!==t[e.id]&&this._throwError(e,t),t[e.id]=Object.keys(t).length}_throwError(e,t){Object.keys(t);let n={};for(let e in t)n[t[e]]=e;throw(n=Object.values(n)).push(e.id),new i(`Circular: ${n}`)}}}},function(e,t){e.exports={QueueEvent:{START:"start",DONE:"done",PAUSED:"paused",RESUMED:"resumed"}}},function(e,t,i){const{Operation:n}=i(0);e.exports={BlockOperation:class extends n{constructor(){let e,t;const i=arguments[0];if("number"==typeof i){e=i;const n=arguments[1];"function"==typeof n&&(t=n)}else{if("function"!=typeof i)throw new Error("Wrong arguments passed: missing ID and/or function");t=i}super(e),this.block=t}run(){return this.block()}}}},function(e,t,i){const{Operation:n}=i(0),{OperationQueue:r}=i(4);e.exports={GroupOperation:class extends n{constructor(){super(),this.queue=new r,this.operations=[]}async run(){return await this.queue.addOperations(this.operations),this.operations.reduce((e,t)=>(e.push(t.result),e),[])}async start(){return this.dependencies=[],super.start()}addOperation(e){this.operations.push(e),this.dependencies=[]}addOperations(e){this.operations=this.operations.concat(e),this.dependencies=[]}}}}]); //# sourceMappingURL=operationkit.min.js.map \ No newline at end of file diff --git a/dist/operationkit.min.js.map b/dist/operationkit.min.js.map index 4ee3127..5a0a266 100644 --- a/dist/operationkit.min.js.map +++ b/dist/operationkit.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./src/Operation.js","webpack:///./src/QueuePriority.js","webpack:///./src/OperationEvent.js","webpack:///./src/OperationQueue.js","webpack:///./src/index.js","webpack:///./node_modules/events/events.js","webpack:///./node_modules/uuid/v4.js","webpack:///./node_modules/uuid/lib/rng-browser.js","webpack:///./node_modules/uuid/lib/bytesToUuid.js","webpack:///./src/utils.js","webpack:///./src/CircularOperationCheck.js","webpack:///./src/BlockOperation.js","webpack:///./src/GroupOperation.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","EventEmitter","uuidv4","OperationEvent","QueuePriority","copyArray","Operation","[object Object]","id","this","ee","_dependencies","completionCallback","map","isExecuting","_done","_isInQueue","_canStart","_cancelled","error","promise","runPromise","_queuePriority","normal","_resolve","_reject","emit","DONE","console","log","result","isFinished","Promise","resolve","CANCEL","isCancelled","isInQueue","queuePriority","isValid","dependencies","event","cb","on","off","dependency","push","filter","operation","Error","START","run","then","done","catch","e","ERROR","err","_preProcessStart","READY","main","reject","_createMap","length","forEach","_onDependantOperationDone","start","_tryStart","_isEmpty","obj","veryLow","low","high","veryHigh","CircularOperationChecker","OperationQueue","time","operations","maximumConcurentOperations","readyQueueMap","readyQueue","runningQueueMap","runningQueue","queues","_isDone","totalTime","Math","abs","getTime","end","Date","addOperations","concat","_preProcessOperations","_begin","_paused","_checkNextOperation","isPaused","op","_onOperationStart","_onOperationReady","_onOperationCancel","_onOperationDone","_startOperations","_startOperation","_hasOperations","_getNextOperation","pop","BlockOperation","GroupOperation","ReflectOwnKeys","R","Reflect","ReflectApply","apply","target","receiver","args","Function","ownKeys","getOwnPropertySymbols","getOwnPropertyNames","NumberIsNaN","Number","isNaN","init","_events","undefined","_eventsCount","_maxListeners","defaultMaxListeners","$getMaxListeners","that","_addListener","type","listener","prepend","events","existing","warning","TypeError","newListener","unshift","warned","w","String","emitter","count","warn","_onceWrap","state","fired","wrapFn","wrapped","arguments","removeListener","_listeners","unwrap","evlistener","arr","ret","Array","unwrapListeners","arrayClone","listenerCount","copy","set","arg","RangeError","getPrototypeOf","setMaxListeners","getMaxListeners","doError","er","message","context","handler","len","listeners","addListener","prependListener","once","prependOnceListener","list","position","originalListener","shift","index","spliceOne","removeAllListeners","keys","rawListeners","eventNames","rng","bytesToUuid","options","buf","offset","rnds","random","ii","getRandomValues","crypto","window","msCrypto","rnds8","Uint8Array","byteToHex","toString","substr","bth","join","array","assign","copyObject","CircularOperationError","super","_checkCircular","_verifyOpMap","_checkDependencies","mapHash","JSON","parse","stringify","_throwError","values","block","first","second","queue","reduce","accum"],"mappings":"aACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI,EAAAL,GAAAM,KAAAJ,EAAAD,QAAAC,IAAAD,QAAAF,GAGAG,EAAAE,GAAA,EAGAF,EAAAD,QAKAF,EAAAQ,EAAAF,EAGAN,EAAAS,EAAAV,EAGAC,EAAAU,EAAA,SAAAR,EAAAS,EAAAC,GACAZ,EAAAa,EAAAX,EAAAS,IACAG,OAAAC,eAAAb,EAAAS,EAAA,CAA0CK,YAAA,EAAAC,IAAAL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ACA,mBAAA0E,IACAF,EAAAE,OAES,mBAAAD,IACTD,EAAAC,GAGAX,MAAA/M,GACAC,KAAAwN,QAGA1N,MACA,OAAAE,KAAAwN,4BCxBA,MAAA3N,UAAOA,GAAezC,EAAQ,IAC9B6G,eAAOA,GAAoB7G,EAAQ,GAiDnCG,EAAAD,QAAA,CACA6I,eAhDA,cAAAtG,EAEAC,cACAgN,QACA9M,KAAA2N,MAAA,IAAA1J,EACAjE,KAAAmE,WAAA,GAQArE,YAGA,aAFAE,KAAA2N,MAAA1I,cAAAjF,KAAAmE,YAEAnE,KAAAmE,WAAAyJ,OAAA,CAAAC,EAAAvL,KACAuL,EAAAzL,KAAAE,EAAAjB,QACAwM,GACS,IAMT/N,cAEA,OADAE,KAAA8B,aAAA,GACAgL,MAAAtJ,QAMA1D,aAAAwC,GACAtC,KAAAmE,WAAA/B,KAAAE,GACAtC,KAAA8B,aAAA,GAMAhC,cAAAqE,GACAnE,KAAAmE,WAAAnE,KAAAmE,WAAAe,OAAAf,GACAnE,KAAA8B,aAAA","file":"operationkit.min.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 4);\n","const EventEmitter = require('events')\nconst uuidv4 = require('uuid/v4');\n\nconst { OperationEvent } = require('./OperationEvent');\nconst { QueuePriority } = require('./QueuePriority');\nconst { copyArray } = require('./utils');\n\nclass Operation {\n\n constructor(id) {\n if (!id) {\n id = uuidv4()\n }\n\n this.id = id;\n this.ee = new EventEmitter();\n this._dependencies = [];\n this.completionCallback = null;\n this.map = {};\n this.isExecuting = false;\n this._done = false;\n this._isInQueue = false;\n this._canStart = false;\n this._cancelled = false;\n this.error = true;\n this.name = null;\n this.promise = null;\n this.runPromise = null;\n this._queuePriority = QueuePriority.normal;\n\n this._resolve = null;\n this._reject = null;\n }\n\n done() {\n this._done = true;\n this.completionCallback && this.completionCallback(this);\n this.ee.emit(OperationEvent.DONE, this);\n console.log(`done: ${this.id}`);\n this._resolve && this._resolve(this.result);\n }\n\n isDone() {\n return this._done;\n }\n\n get isFinished() {\n return this._done;\n }\n \n cancel() {\n this._cancelled = true;\n Promise.resolve(this.promise);\n this.ee.emit(OperationEvent.CANCEL, this);\n this._resolve && this._resolve();\n }\n\n get isCancelled() {\n return this._cancelled;\n }\n\n set isInQueue(value) {\n this._isInQueue = value;\n }\n\n get isInQueue() {\n return this._isInQueue;\n }\n\n set queuePriority(value) {\n if (this.isExecuting || this.isCancelled || this.isFinished) {\n return;\n }\n\n if (QueuePriority.isValid(value)) {\n this._queuePriority = value;\n }\n }\n\n get queuePriority() {\n return this._queuePriority;\n }\n\n set dependencies(value) {\n if (this.isExecuting || this.isCancelled || this.isFinished) {\n return;\n }\n\n this._dependencies = value;\n }\n\n get dependencies() {\n if (this.isExecuting || this.isCancelled || this.isFinished) {\n return copyArray(this._dependencies);\n }\n return this._dependencies;\n }\n\n on(event, cb) {\n this.ee.on(event, cb);\n }\n\n off(event, cb) {\n this.ee.off(event, cb);\n }\n\n addDependency(dependency) {\n this._dependencies.push(dependency);\n }\n\n removeDependency(dependency) {\n this._dependencies = this._dependencies.filter(operation => operation.id !== dependency.id)\n }\n\n /**\n * @abstract\n * Needs to be implemented by sub-class\n * Task to be executed\n */\n async run() {\n throw new Error('run function must be implemented');\n }\n\n main() {\n this.isExecuting = true;\n this.ee.emit(OperationEvent.START, this);\n this.runPromise = this.run()\n .then(result => {\n this.result = result;\n this.done();\n })\n .catch(e => {\n this.isExecuting = false;\n this.error = true;\n this.ee.emit(OperationEvent.ERROR, {err: e, operation: this});\n this.ee.emit(OperationEvent.DONE, this);\n this._reject && this._reject();\n });\n }\n\n start() {\n if (this.isExecuting || this.isCancelled || this.isFinished) {\n return this.promise;\n } else if (this.promise && !this._canStart) {\n this._preProcessStart();\n } else if (this.promise && this._canStart) {\n if (this._isInQueue) {\n this.ee.emit(OperationEvent.READY, this);\n } else {\n this.main();\n }\n } else {\n this.promise = new Promise((resolve, reject) => {\n this._resolve = resolve;\n this._reject = reject;\n this._preProcessStart();\n });\n }\n return this.promise;\n }\n\n _preProcessStart() {\n this._createMap();\n\n if (this._canStart) {\n if (this._isInQueue) {\n this.ee.emit(OperationEvent.READY, this);\n } else {\n this.main();\n }\n }\n }\n\n _createMap() {\n if (!this._dependencies.length) {\n this._canStart = true;\n return;\n }\n\n this._dependencies.forEach(operation => {\n this.map[operation.id] = true;\n operation.on(OperationEvent.DONE, this._onDependantOperationDone.bind(this));\n operation.start();\n });\n\n }\n\n _onDependantOperationDone(operation) {\n delete this.map[operation.id];\n this._tryStart();\n }\n\n _tryStart() {\n if (this.isExecuting || this.isCancelled || this.isFinished) {\n return;\n }\n if (this._isEmpty(this.map)) {\n // should emit event to let operation queue that this operation can start\n // then it could check if maximum concurrent is not passed\n this._canStart = true;\n if (this.isInQueue) {\n this.ee.emit(OperationEvent.READY, this);\n } else {\n this.start();\n }\n }\n }\n\n _isEmpty(obj) {\n for(var key in obj) {\n if(obj.hasOwnProperty(key))\n return false;\n }\n return true;\n }\n}\n\nmodule.exports = {\n Operation\n}","const QueuePriority = {\n veryLow: 0,\n low: 1,\n normal: 2,\n high: 3,\n veryHigh: 4,\n isValid(value) {\n return value >= QueuePriority.veryLow && value <= QueuePriority.veryHigh;\n }\n}\n\nmodule.exports = {\n QueuePriority\n}","\nconst OperationEvent = {\n START: 'start',\n READY: 'ready',\n DONE: 'done',\n CANCEL: 'cancel',\n ERROR: 'e'\n}\n\nmodule.exports = {\n OperationEvent\n}","const { CircularOperationChecker } = require('./CircularOperationCheck');\nconst { QueuePriority } = require('./QueuePriority');\n\nclass OperationQueue {\n\n constructor() {\n this.time = {};\n this.map = {};\n this.operations = [];\n this.resolve = null;\n this.completionCallback = null;\n this.maximumConcurentOperations = 10;\n\n this.readyQueueMap = {};\n this.readyQueue = [];\n\n this.runningQueueMap = {};\n this.runningQueue = [];\n\n this.queues = {\n [QueuePriority.veryHigh]: [],\n [QueuePriority.high]: [],\n [QueuePriority.normal]: [],\n [QueuePriority.low]: [],\n [QueuePriority.veryLow]: []\n }\n\n this._isDone = false;\n }\n\n get totalTime() {\n return Math.abs((this.time.start.getTime() - this.time.end.getTime()) / 1000);\n }\n\n get isExecuting() {\n return !this._isEmpty(this.map);\n }\n\n done() {\n if (this._isDone) {\n return;\n }\n \n this.time.end = new Date();\n this._isDone = true;\n this.completionCallback && this.completionCallback();\n this.resolve();\n }\n\n /**\n * \n * @param {Operation} operation \n */\n async addOperation(operation) {\n return this.addOperations([operation]);\n }\n\n /**\n * \n * @param {Array.} operations\n */\n async addOperations(operations) {\n this.operations = this.operations.concat(operations);\n this._preProcessOperations(this.operations);\n return this._begin();\n }\n\n pause() {\n this._paused = true;\n }\n\n resume() {\n this._paused = false;\n this._checkNextOperation();\n }\n\n get isPaused() {\n return this._paused;\n }\n\n _preProcessOperations(operations) {\n operations.forEach(op => {\n if (!this.map[op.id]) {\n this.map[op.id] = true;\n op.isInQueue = true;\n op.on('start', this._onOperationStart.bind(this));\n op.on('ready', this._onOperationReady.bind(this));\n op.on('cancel', this._onOperationCancel.bind(this));\n op.on('done', this._onOperationDone.bind(this));\n };\n this._preProcessOperations(op.dependencies);\n })\n }\n\n _begin() {\n if (this.promise) {\n this._startOperations();\n } else {\n this.promise = new Promise((resolve, reject) => {\n try {\n new CircularOperationChecker(this.operations);\n } catch (e) {\n return reject(e);\n }\n this.time.start = new Date();\n this.resolve = resolve;\n \n this._startOperations();\n });\n }\n\n return this.promise;\n }\n\n _startOperations() {\n this.operations.forEach(operation => {\n this._startOperation(operation);\n });\n }\n\n _startOperation(operation) {\n operation.start();\n }\n\n _onOperationStart(operation) {\n //\n }\n\n _onOperationReady(operation) {\n if (this.readyQueueMap[operation.id]) {\n return;\n }\n this.readyQueueMap[operation.id] = true;\n this.queues[operation.queuePriority].push(operation);\n\n this._checkNextOperation() \n }\n\n _onOperationDone(operation) {\n this.runningQueue = this.runningQueue.filter(op => op.id !== operation.id);\n\n delete this.map[operation.id];\n delete this.runningQueueMap[operation.id];\n\n if (this._isEmpty(this.map)) {\n this.done();\n } else {\n this._checkNextOperation();\n }\n }\n\n _checkNextOperation() {\n if (this._paused) {\n return;\n }\n\n if (this.runningQueue.length < this.maximumConcurentOperations && this._hasOperations()) {\n const operation = this._getNextOperation();\n if (!operation.isExecuting || !operation.isCancelled || !this.runningQueueMap[operation.id]) {\n this.runningQueueMap[operation.id] = true;\n this.runningQueue.push(operation);\n operation.main();\n this._checkNextOperation()\n }\n }\n }\n\n _hasOperations() {\n return !!(this.queues[QueuePriority.veryHigh].length\n + this.queues[QueuePriority.high].length\n + this.queues[QueuePriority.normal].length\n + this.queues[QueuePriority.low].length\n + this.queues[QueuePriority.veryLow].length);\n }\n\n _getNextOperation() {\n if (this.queues[QueuePriority.veryHigh].length) {\n return this.queues[QueuePriority.veryHigh].pop();\n } else if (this.queues[QueuePriority.high].length) {\n return this.queues[QueuePriority.high].pop();\n } else if (this.queues[QueuePriority.normal].length) {\n return this.queues[QueuePriority.normal].pop();\n } else if (this.queues[QueuePriority.low].length) {\n return this.queues[QueuePriority.low].pop();\n } else if (this.queues[QueuePriority.veryLow].length) {\n return this.queues[QueuePriority.veryLow].pop();\n }\n }\n\n\n _onOperationCancel(operation) {\n delete this.map[operation.id];\n if (this._isEmpty(this.map)) {\n this.done();\n }\n }\n\n _isEmpty(obj) {\n for(var key in obj) {\n if(obj.hasOwnProperty(key))\n return false;\n }\n return true;\n }\n}\n\nmodule.exports = {\n OperationQueue\n}","\nconst { Operation } = require('./Operation');\nconst { OperationQueue } = require('./OperationQueue');\nconst { BlockOperation } = require('./BlockOperation');\nconst { GroupOperation } = require('./GroupOperation');\nconst { OperationEvent } = require('./OperationEvent');\nconst { QueuePriority } = require('./QueuePriority');\n\nmodule.exports = {\n Operation,\n OperationQueue,\n BlockOperation,\n GroupOperation,\n OperationEvent,\n QueuePriority\n};","// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n'use strict';\n\nvar R = typeof Reflect === 'object' ? Reflect : null\nvar ReflectApply = R && typeof R.apply === 'function'\n ? R.apply\n : function ReflectApply(target, receiver, args) {\n return Function.prototype.apply.call(target, receiver, args);\n }\n\nvar ReflectOwnKeys\nif (R && typeof R.ownKeys === 'function') {\n ReflectOwnKeys = R.ownKeys\n} else if (Object.getOwnPropertySymbols) {\n ReflectOwnKeys = function ReflectOwnKeys(target) {\n return Object.getOwnPropertyNames(target)\n .concat(Object.getOwnPropertySymbols(target));\n };\n} else {\n ReflectOwnKeys = function ReflectOwnKeys(target) {\n return Object.getOwnPropertyNames(target);\n };\n}\n\nfunction ProcessEmitWarning(warning) {\n if (console && console.warn) console.warn(warning);\n}\n\nvar NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {\n return value !== value;\n}\n\nfunction EventEmitter() {\n EventEmitter.init.call(this);\n}\nmodule.exports = EventEmitter;\n\n// Backwards-compat with node 0.10.x\nEventEmitter.EventEmitter = EventEmitter;\n\nEventEmitter.prototype._events = undefined;\nEventEmitter.prototype._eventsCount = 0;\nEventEmitter.prototype._maxListeners = undefined;\n\n// By default EventEmitters will print a warning if more than 10 listeners are\n// added to it. This is a useful default which helps finding memory leaks.\nvar defaultMaxListeners = 10;\n\nObject.defineProperty(EventEmitter, 'defaultMaxListeners', {\n enumerable: true,\n get: function() {\n return defaultMaxListeners;\n },\n set: function(arg) {\n if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {\n throw new RangeError('The value of \"defaultMaxListeners\" is out of range. It must be a non-negative number. Received ' + arg + '.');\n }\n defaultMaxListeners = arg;\n }\n});\n\nEventEmitter.init = function() {\n\n if (this._events === undefined ||\n this._events === Object.getPrototypeOf(this)._events) {\n this._events = Object.create(null);\n this._eventsCount = 0;\n }\n\n this._maxListeners = this._maxListeners || undefined;\n};\n\n// Obviously not all Emitters should be limited to 10. This function allows\n// that to be increased. Set to zero for unlimited.\nEventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {\n if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {\n throw new RangeError('The value of \"n\" is out of range. It must be a non-negative number. Received ' + n + '.');\n }\n this._maxListeners = n;\n return this;\n};\n\nfunction $getMaxListeners(that) {\n if (that._maxListeners === undefined)\n return EventEmitter.defaultMaxListeners;\n return that._maxListeners;\n}\n\nEventEmitter.prototype.getMaxListeners = function getMaxListeners() {\n return $getMaxListeners(this);\n};\n\nEventEmitter.prototype.emit = function emit(type) {\n var args = [];\n for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);\n var doError = (type === 'error');\n\n var events = this._events;\n if (events !== undefined)\n doError = (doError && events.error === undefined);\n else if (!doError)\n return false;\n\n // If there is no 'error' event listener then throw.\n if (doError) {\n var er;\n if (args.length > 0)\n er = args[0];\n if (er instanceof Error) {\n // Note: The comments on the `throw` lines are intentional, they show\n // up in Node's output if this results in an unhandled exception.\n throw er; // Unhandled 'error' event\n }\n // At least give some kind of context to the user\n var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));\n err.context = er;\n throw err; // Unhandled 'error' event\n }\n\n var handler = events[type];\n\n if (handler === undefined)\n return false;\n\n if (typeof handler === 'function') {\n ReflectApply(handler, this, args);\n } else {\n var len = handler.length;\n var listeners = arrayClone(handler, len);\n for (var i = 0; i < len; ++i)\n ReflectApply(listeners[i], this, args);\n }\n\n return true;\n};\n\nfunction _addListener(target, type, listener, prepend) {\n var m;\n var events;\n var existing;\n\n if (typeof listener !== 'function') {\n throw new TypeError('The \"listener\" argument must be of type Function. Received type ' + typeof listener);\n }\n\n events = target._events;\n if (events === undefined) {\n events = target._events = Object.create(null);\n target._eventsCount = 0;\n } else {\n // To avoid recursion in the case that type === \"newListener\"! Before\n // adding it to the listeners, first emit \"newListener\".\n if (events.newListener !== undefined) {\n target.emit('newListener', type,\n listener.listener ? listener.listener : listener);\n\n // Re-assign `events` because a newListener handler could have caused the\n // this._events to be assigned to a new object\n events = target._events;\n }\n existing = events[type];\n }\n\n if (existing === undefined) {\n // Optimize the case of one listener. Don't need the extra array object.\n existing = events[type] = listener;\n ++target._eventsCount;\n } else {\n if (typeof existing === 'function') {\n // Adding the second element, need to change to array.\n existing = events[type] =\n prepend ? [listener, existing] : [existing, listener];\n // If we've already got an array, just append.\n } else if (prepend) {\n existing.unshift(listener);\n } else {\n existing.push(listener);\n }\n\n // Check for listener leak\n m = $getMaxListeners(target);\n if (m > 0 && existing.length > m && !existing.warned) {\n existing.warned = true;\n // No error code for this since it is a Warning\n // eslint-disable-next-line no-restricted-syntax\n var w = new Error('Possible EventEmitter memory leak detected. ' +\n existing.length + ' ' + String(type) + ' listeners ' +\n 'added. Use emitter.setMaxListeners() to ' +\n 'increase limit');\n w.name = 'MaxListenersExceededWarning';\n w.emitter = target;\n w.type = type;\n w.count = existing.length;\n ProcessEmitWarning(w);\n }\n }\n\n return target;\n}\n\nEventEmitter.prototype.addListener = function addListener(type, listener) {\n return _addListener(this, type, listener, false);\n};\n\nEventEmitter.prototype.on = EventEmitter.prototype.addListener;\n\nEventEmitter.prototype.prependListener =\n function prependListener(type, listener) {\n return _addListener(this, type, listener, true);\n };\n\nfunction onceWrapper() {\n var args = [];\n for (var i = 0; i < arguments.length; i++) args.push(arguments[i]);\n if (!this.fired) {\n this.target.removeListener(this.type, this.wrapFn);\n this.fired = true;\n ReflectApply(this.listener, this.target, args);\n }\n}\n\nfunction _onceWrap(target, type, listener) {\n var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };\n var wrapped = onceWrapper.bind(state);\n wrapped.listener = listener;\n state.wrapFn = wrapped;\n return wrapped;\n}\n\nEventEmitter.prototype.once = function once(type, listener) {\n if (typeof listener !== 'function') {\n throw new TypeError('The \"listener\" argument must be of type Function. Received type ' + typeof listener);\n }\n this.on(type, _onceWrap(this, type, listener));\n return this;\n};\n\nEventEmitter.prototype.prependOnceListener =\n function prependOnceListener(type, listener) {\n if (typeof listener !== 'function') {\n throw new TypeError('The \"listener\" argument must be of type Function. Received type ' + typeof listener);\n }\n this.prependListener(type, _onceWrap(this, type, listener));\n return this;\n };\n\n// Emits a 'removeListener' event if and only if the listener was removed.\nEventEmitter.prototype.removeListener =\n function removeListener(type, listener) {\n var list, events, position, i, originalListener;\n\n if (typeof listener !== 'function') {\n throw new TypeError('The \"listener\" argument must be of type Function. Received type ' + typeof listener);\n }\n\n events = this._events;\n if (events === undefined)\n return this;\n\n list = events[type];\n if (list === undefined)\n return this;\n\n if (list === listener || list.listener === listener) {\n if (--this._eventsCount === 0)\n this._events = Object.create(null);\n else {\n delete events[type];\n if (events.removeListener)\n this.emit('removeListener', type, list.listener || listener);\n }\n } else if (typeof list !== 'function') {\n position = -1;\n\n for (i = list.length - 1; i >= 0; i--) {\n if (list[i] === listener || list[i].listener === listener) {\n originalListener = list[i].listener;\n position = i;\n break;\n }\n }\n\n if (position < 0)\n return this;\n\n if (position === 0)\n list.shift();\n else {\n spliceOne(list, position);\n }\n\n if (list.length === 1)\n events[type] = list[0];\n\n if (events.removeListener !== undefined)\n this.emit('removeListener', type, originalListener || listener);\n }\n\n return this;\n };\n\nEventEmitter.prototype.off = EventEmitter.prototype.removeListener;\n\nEventEmitter.prototype.removeAllListeners =\n function removeAllListeners(type) {\n var listeners, events, i;\n\n events = this._events;\n if (events === undefined)\n return this;\n\n // not listening for removeListener, no need to emit\n if (events.removeListener === undefined) {\n if (arguments.length === 0) {\n this._events = Object.create(null);\n this._eventsCount = 0;\n } else if (events[type] !== undefined) {\n if (--this._eventsCount === 0)\n this._events = Object.create(null);\n else\n delete events[type];\n }\n return this;\n }\n\n // emit removeListener for all listeners on all events\n if (arguments.length === 0) {\n var keys = Object.keys(events);\n var key;\n for (i = 0; i < keys.length; ++i) {\n key = keys[i];\n if (key === 'removeListener') continue;\n this.removeAllListeners(key);\n }\n this.removeAllListeners('removeListener');\n this._events = Object.create(null);\n this._eventsCount = 0;\n return this;\n }\n\n listeners = events[type];\n\n if (typeof listeners === 'function') {\n this.removeListener(type, listeners);\n } else if (listeners !== undefined) {\n // LIFO order\n for (i = listeners.length - 1; i >= 0; i--) {\n this.removeListener(type, listeners[i]);\n }\n }\n\n return this;\n };\n\nfunction _listeners(target, type, unwrap) {\n var events = target._events;\n\n if (events === undefined)\n return [];\n\n var evlistener = events[type];\n if (evlistener === undefined)\n return [];\n\n if (typeof evlistener === 'function')\n return unwrap ? [evlistener.listener || evlistener] : [evlistener];\n\n return unwrap ?\n unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);\n}\n\nEventEmitter.prototype.listeners = function listeners(type) {\n return _listeners(this, type, true);\n};\n\nEventEmitter.prototype.rawListeners = function rawListeners(type) {\n return _listeners(this, type, false);\n};\n\nEventEmitter.listenerCount = function(emitter, type) {\n if (typeof emitter.listenerCount === 'function') {\n return emitter.listenerCount(type);\n } else {\n return listenerCount.call(emitter, type);\n }\n};\n\nEventEmitter.prototype.listenerCount = listenerCount;\nfunction listenerCount(type) {\n var events = this._events;\n\n if (events !== undefined) {\n var evlistener = events[type];\n\n if (typeof evlistener === 'function') {\n return 1;\n } else if (evlistener !== undefined) {\n return evlistener.length;\n }\n }\n\n return 0;\n}\n\nEventEmitter.prototype.eventNames = function eventNames() {\n return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];\n};\n\nfunction arrayClone(arr, n) {\n var copy = new Array(n);\n for (var i = 0; i < n; ++i)\n copy[i] = arr[i];\n return copy;\n}\n\nfunction spliceOne(list, index) {\n for (; index + 1 < list.length; index++)\n list[index] = list[index + 1];\n list.pop();\n}\n\nfunction unwrapListeners(arr) {\n var ret = new Array(arr.length);\n for (var i = 0; i < ret.length; ++i) {\n ret[i] = arr[i].listener || arr[i];\n }\n return ret;\n}\n","var rng = require('./lib/rng');\nvar bytesToUuid = require('./lib/bytesToUuid');\n\nfunction v4(options, buf, offset) {\n var i = buf && offset || 0;\n\n if (typeof(options) == 'string') {\n buf = options === 'binary' ? new Array(16) : null;\n options = null;\n }\n options = options || {};\n\n var rnds = options.random || (options.rng || rng)();\n\n // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n\n // Copy bytes to buffer, if provided\n if (buf) {\n for (var ii = 0; ii < 16; ++ii) {\n buf[i + ii] = rnds[ii];\n }\n }\n\n return buf || bytesToUuid(rnds);\n}\n\nmodule.exports = v4;\n","// Unique ID creation requires a high quality random # generator. In the\n// browser this is a little complicated due to unknown quality of Math.random()\n// and inconsistent support for the `crypto` API. We do the best we can via\n// feature-detection\n\n// getRandomValues needs to be invoked in a context where \"this\" is a Crypto\n// implementation. Also, find the complete implementation of crypto on IE11.\nvar getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto)) ||\n (typeof(msCrypto) != 'undefined' && typeof window.msCrypto.getRandomValues == 'function' && msCrypto.getRandomValues.bind(msCrypto));\n\nif (getRandomValues) {\n // WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto\n var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef\n\n module.exports = function whatwgRNG() {\n getRandomValues(rnds8);\n return rnds8;\n };\n} else {\n // Math.random()-based (RNG)\n //\n // If all else fails, use Math.random(). It's fast, but is of unspecified\n // quality.\n var rnds = new Array(16);\n\n module.exports = function mathRNG() {\n for (var i = 0, r; i < 16; i++) {\n if ((i & 0x03) === 0) r = Math.random() * 0x100000000;\n rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;\n }\n\n return rnds;\n };\n}\n","/**\n * Convert array of 16 byte values to UUID string format of the form:\n * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n */\nvar byteToHex = [];\nfor (var i = 0; i < 256; ++i) {\n byteToHex[i] = (i + 0x100).toString(16).substr(1);\n}\n\nfunction bytesToUuid(buf, offset) {\n var i = offset || 0;\n var bth = byteToHex;\n // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4\n return ([bth[buf[i++]], bth[buf[i++]], \n\tbth[buf[i++]], bth[buf[i++]], '-',\n\tbth[buf[i++]], bth[buf[i++]], '-',\n\tbth[buf[i++]], bth[buf[i++]], '-',\n\tbth[buf[i++]], bth[buf[i++]], '-',\n\tbth[buf[i++]], bth[buf[i++]],\n\tbth[buf[i++]], bth[buf[i++]],\n\tbth[buf[i++]], bth[buf[i++]]]).join('');\n}\n\nmodule.exports = bytesToUuid;\n","const copyArray = array => {\n return array.map(object => Object.assign(Object.create(object), object))\n}\n\nconst copyObject = object => {\n return Object.assign(Object.create(object), object);\n}\n\nmodule.exports = {\n copyArray,\n copyObject,\n}","\nclass CircularOperationError extends Error {\n constructor(message = 'Circular dependency') {\n super()\n this.message = message;\n }\n}\n\nclass CircularOperationChecker {\n\n constructor(operations) {\n this.operations = operations\n this._checkCircular();\n }\n\n _checkCircular() {\n this.operations.forEach(operation => {\n operation.dependencies.forEach(op => {\n let map = {};\n map[operation.id] = Object.keys(map).length;\n this._verifyOpMap(op, map); \n this._checkDependencies(op, map)\n });\n });\n }\n\n _checkDependencies(operation, mapHash) {\n operation.dependencies.forEach(op => {\n let map = JSON.parse(JSON.stringify(mapHash));\n this._verifyOpMap(op, map);\n this._checkDependencies(op, map)\n })\n }\n\n _verifyOpMap(op, map) {\n if (map[op.id] !== undefined) {\n this._throwError(op, map)\n }\n\n map[op.id] = Object.keys(map).length;\n }\n\n _throwError() {\n let keys = Object.keys(map);\n\n let values = {};\n for (let key in map) {\n const value = map[key];\n values[value] = key;\n }\n\n values = Object.values(values);\n values.push(op.id);\n throw new CircularOperationError(`Circular: ${values}`);\n }\n\n}\n\nmodule.exports = {\n CircularOperationChecker\n}","const { Operation } = require('./Operation');\n\nclass BlockOperation extends Operation {\n\n constructor() {\n let id;\n let block;\n\n const first = arguments[0];\n if (typeof first === 'number') {\n id = first;\n const second = arguments[1];\n if (typeof second === 'function') {\n block = second;\n }\n } else if (typeof first === 'function') {\n block = first;\n }\n \n super(id);\n this.block = block;\n }\n\n run() {\n return this.block();\n }\n}\n\nmodule.exports = {\n BlockOperation\n}","const { Operation } = require('./Operation');\nconst { OperationQueue } = require('./OperationQueue');\n\nclass GroupOperation extends Operation {\n\n constructor() {\n super();\n this.queue = new OperationQueue(); \n this.operations = [];\n }\n\n /**\n * @override\n * \n * @returns {Promise}\n */\n async run() {\n await this.queue.addOperations(this.operations)\n\n return this.operations.reduce((accum, operation) => {\n accum.push(operation.result);\n return accum;\n }, []); \n }\n\n /**\n * @override\n */\n async start() {\n this.dependencies = [];\n return super.start();\n }\n\n /**\n * @param {Operation} operation \n */\n addOperation(operation) {\n this.operations.push(operation);\n this.dependencies = [];\n }\n\n /**\n * @param {Array.} operation \n */\n addOperations(operations) {\n this.operations = this.operations.concat(operations);\n this.dependencies = [];\n }\n}\n\nmodule.exports = {\n GroupOperation\n}"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./src/Operation.js","webpack:///./src/QueuePriority.js","webpack:///./node_modules/events/events.js","webpack:///./src/OperationEvent.js","webpack:///./src/OperationQueue.js","webpack:///./src/index.js","webpack:///./node_modules/uuid/v4.js","webpack:///./node_modules/uuid/lib/rng-browser.js","webpack:///./node_modules/uuid/lib/bytesToUuid.js","webpack:///./src/utils.js","webpack:///./src/CircularOperationValidator.js","webpack:///./src/QueueEvent.js","webpack:///./src/BlockOperation.js","webpack:///./src/GroupOperation.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","EventEmitter","uuidv4","OperationEvent","QueuePriority","copyArray","Operation","[object Object]","id","this","ee","_dependencies","completionCallback","map","isExecuting","_done","_isInQueue","_canStart","_cancelled","error","promise","runPromise","_queuePriority","normal","_resolve","_reject","emit","DONE","result","isFinished","Promise","resolve","CANCEL","isCancelled","isInQueue","queuePriority","isValid","dependencies","event","cb","on","off","dependency","push","filter","operation","Error","START","run","then","done","catch","e","ERROR","err","_preProcessStart","READY","main","reject","_createMap","length","forEach","_onDependantOperationDone","start","_tryStart","_isEmpty","obj","veryLow","low","high","veryHigh","ReflectOwnKeys","R","Reflect","ReflectApply","apply","target","receiver","args","Function","ownKeys","getOwnPropertySymbols","getOwnPropertyNames","concat","NumberIsNaN","Number","isNaN","init","_events","undefined","_eventsCount","_maxListeners","defaultMaxListeners","$getMaxListeners","that","_addListener","type","listener","prepend","events","existing","warning","TypeError","newListener","unshift","warned","w","String","emitter","count","console","warn","_onceWrap","state","fired","wrapFn","wrapped","arguments","removeListener","_listeners","unwrap","evlistener","arr","ret","Array","unwrapListeners","arrayClone","listenerCount","copy","set","arg","RangeError","getPrototypeOf","setMaxListeners","getMaxListeners","doError","er","message","context","handler","len","listeners","addListener","prependListener","once","prependOnceListener","list","position","originalListener","shift","index","pop","spliceOne","removeAllListeners","keys","rawListeners","eventNames","CircularOperationValidator","QueueEvent","OperationQueue","time","operations","_processedOperations","maximumConcurentOperations","readyQueueMap","readyQueue","runningQueueMap","runningQueue","queues","_isDone","totalTime","Math","abs","getTime","end","Date","addOperations","_preProcessOperations","_begin","_paused","_checkNextOperation","isPaused","op","_bindOperation","_onOperationStart","_onOperationReady","_onOperationCancel","_onOperationDone","_startOperations","_startOperation","_unbindOperation","_hasOperations","_getNextOperation","BlockOperation","GroupOperation","rng","bytesToUuid","options","buf","offset","rnds","random","ii","getRandomValues","crypto","window","msCrypto","rnds8","Uint8Array","byteToHex","toString","substr","bth","join","array","assign","copyObject","CircularOperationValidatorError","super","_checkCircular","_verifyOpMap","_checkDependencies","mapHash","JSON","parse","stringify","_throwError","values","PAUSED","RESUMED","block","first","second","queue","reduce","accum"],"mappings":"aACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAC,QAGA,IAAAC,EAAAJ,EAAAE,GAAA,CACAG,EAAAH,EACAI,GAAA,EACAH,QAAA,IAUA,OANAI,EAAAL,GAAAM,KAAAJ,EAAAD,QAAAC,IAAAD,QAAAF,GAGAG,EAAAE,GAAA,EAGAF,EAAAD,QAKAF,EAAAQ,EAAAF,EAGAN,EAAAS,EAAAV,EAGAC,EAAAU,EAAA,SAAAR,EAAAS,EAAAC,GACAZ,EAAAa,EAAAX,EAAAS,IACAG,OAAAC,eAAAb,EAAAS,EAAA,CAA0CK,YAAA,EAAAC,IAAAL,KAK1CZ,EAAAkB,EAAA,SAAAhB,GACA,oBAAAiB,eAAAC,aACAN,OAAAC,eAAA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KAAA4B,aAAA,GAMA9B,cAAA0J,GACAxJ,KAAAwJ,WAAAxJ,KAAAwJ,WAAA9E,OAAA8E,GACAxJ,KAAA4B,aAAA","file":"operationkit.min.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 5);\n","const EventEmitter = require('events')\nconst uuidv4 = require('uuid/v4');\n\nconst { OperationEvent } = require('./OperationEvent');\nconst { QueuePriority } = require('./QueuePriority');\nconst { copyArray } = require('./utils');\n\nclass Operation {\n\n constructor(id) {\n if (!id) {\n id = uuidv4()\n }\n\n this.id = id;\n this.ee = new EventEmitter();\n this._dependencies = [];\n this.completionCallback = null;\n this.map = {};\n this.isExecuting = false;\n this._done = false;\n this._isInQueue = false;\n this._canStart = false;\n this._cancelled = false;\n this.error = true;\n this.name = null;\n this.promise = null;\n this.runPromise = null;\n this._queuePriority = QueuePriority.normal;\n\n this._resolve = null;\n this._reject = null;\n }\n\n done() {\n this._done = true;\n this.completionCallback && this.completionCallback(this);\n this.ee.emit(OperationEvent.DONE, this);\n this._resolve && this._resolve(this.result);\n }\n\n isDone() {\n return this._done;\n }\n\n get isFinished() {\n return this._done;\n }\n \n cancel() {\n this._cancelled = true;\n Promise.resolve(this.promise);\n this.ee.emit(OperationEvent.CANCEL, this);\n this._resolve && this._resolve();\n }\n\n get isCancelled() {\n return this._cancelled;\n }\n\n set isInQueue(value) {\n this._isInQueue = value;\n }\n\n get isInQueue() {\n return this._isInQueue;\n }\n\n set queuePriority(value) {\n if (this.isExecuting || this.isCancelled || this.isFinished) {\n return;\n }\n\n if (QueuePriority.isValid(value)) {\n this._queuePriority = value;\n }\n }\n\n get queuePriority() {\n return this._queuePriority;\n }\n\n set dependencies(value) {\n if (this.isExecuting || this.isCancelled || this.isFinished) {\n return;\n }\n\n this._dependencies = value;\n }\n\n get dependencies() {\n if (this.isExecuting || this.isCancelled || this.isFinished) {\n return copyArray(this._dependencies);\n }\n return this._dependencies;\n }\n\n on(event, cb) {\n this.ee.on(event, cb);\n }\n\n off(event, cb) {\n this.ee.off(event, cb);\n }\n\n addDependency(dependency) {\n this._dependencies.push(dependency);\n }\n\n removeDependency(dependency) {\n this._dependencies = this._dependencies.filter(operation => operation.id !== dependency.id)\n }\n\n /**\n * @abstract\n * Needs to be implemented by sub-class\n * Task to be executed\n */\n async run() {\n throw new Error('run function must be implemented');\n }\n\n main() {\n this.isExecuting = true;\n this.ee.emit(OperationEvent.START, this);\n this.runPromise = this.run()\n .then(result => {\n this.result = result;\n this.done();\n })\n .catch(e => {\n this.isExecuting = false;\n this.error = true;\n this.ee.emit(OperationEvent.ERROR, {err: e, operation: this});\n this.ee.emit(OperationEvent.DONE, this);\n this._reject && this._reject();\n });\n }\n\n start() {\n if (this.isExecuting || this.isCancelled || this.isFinished) {\n return this.promise;\n } else if (this.promise && !this._canStart) {\n this._preProcessStart();\n } else if (this.promise && this._canStart) {\n if (this._isInQueue) {\n this.ee.emit(OperationEvent.READY, this);\n } else {\n this.main();\n }\n } else {\n this.promise = new Promise((resolve, reject) => {\n this._resolve = resolve;\n this._reject = reject;\n this._preProcessStart();\n });\n }\n return this.promise;\n }\n\n _preProcessStart() {\n this._createMap();\n\n if (this._canStart) {\n if (this._isInQueue) {\n this.ee.emit(OperationEvent.READY, this);\n } else {\n this.main();\n }\n }\n }\n\n _createMap() {\n if (!this._dependencies.length) {\n this._canStart = true;\n return;\n }\n\n this._dependencies.forEach(operation => {\n this.map[operation.id] = true;\n operation.on(OperationEvent.DONE, this._onDependantOperationDone.bind(this));\n operation.start();\n });\n\n }\n\n _onDependantOperationDone(operation) {\n delete this.map[operation.id];\n this._tryStart();\n }\n\n _tryStart() {\n if (this.isExecuting || this.isCancelled || this.isFinished) {\n return;\n }\n if (this._isEmpty(this.map)) {\n // should emit event to let operation queue that this operation can start\n // then it could check if maximum concurrent is not passed\n this._canStart = true;\n if (this.isInQueue) {\n this.ee.emit(OperationEvent.READY, this);\n } else {\n this.start();\n }\n }\n }\n\n _isEmpty(obj) {\n for(var key in obj) {\n if(obj.hasOwnProperty(key))\n return false;\n }\n return true;\n }\n}\n\nmodule.exports = {\n Operation\n}","const QueuePriority = {\n veryLow: 0,\n low: 1,\n normal: 2,\n high: 3,\n veryHigh: 4,\n isValid(value) {\n return value >= QueuePriority.veryLow && value <= QueuePriority.veryHigh;\n }\n}\n\nmodule.exports = {\n QueuePriority\n}","// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n'use strict';\n\nvar R = typeof Reflect === 'object' ? Reflect : null\nvar ReflectApply = R && typeof R.apply === 'function'\n ? R.apply\n : function ReflectApply(target, receiver, args) {\n return Function.prototype.apply.call(target, receiver, args);\n }\n\nvar ReflectOwnKeys\nif (R && typeof R.ownKeys === 'function') {\n ReflectOwnKeys = R.ownKeys\n} else if (Object.getOwnPropertySymbols) {\n ReflectOwnKeys = function ReflectOwnKeys(target) {\n return Object.getOwnPropertyNames(target)\n .concat(Object.getOwnPropertySymbols(target));\n };\n} else {\n ReflectOwnKeys = function ReflectOwnKeys(target) {\n return Object.getOwnPropertyNames(target);\n };\n}\n\nfunction ProcessEmitWarning(warning) {\n if (console && console.warn) console.warn(warning);\n}\n\nvar NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {\n return value !== value;\n}\n\nfunction EventEmitter() {\n EventEmitter.init.call(this);\n}\nmodule.exports = EventEmitter;\n\n// Backwards-compat with node 0.10.x\nEventEmitter.EventEmitter = EventEmitter;\n\nEventEmitter.prototype._events = undefined;\nEventEmitter.prototype._eventsCount = 0;\nEventEmitter.prototype._maxListeners = undefined;\n\n// By default EventEmitters will print a warning if more than 10 listeners are\n// added to it. This is a useful default which helps finding memory leaks.\nvar defaultMaxListeners = 10;\n\nObject.defineProperty(EventEmitter, 'defaultMaxListeners', {\n enumerable: true,\n get: function() {\n return defaultMaxListeners;\n },\n set: function(arg) {\n if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {\n throw new RangeError('The value of \"defaultMaxListeners\" is out of range. It must be a non-negative number. Received ' + arg + '.');\n }\n defaultMaxListeners = arg;\n }\n});\n\nEventEmitter.init = function() {\n\n if (this._events === undefined ||\n this._events === Object.getPrototypeOf(this)._events) {\n this._events = Object.create(null);\n this._eventsCount = 0;\n }\n\n this._maxListeners = this._maxListeners || undefined;\n};\n\n// Obviously not all Emitters should be limited to 10. This function allows\n// that to be increased. Set to zero for unlimited.\nEventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {\n if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {\n throw new RangeError('The value of \"n\" is out of range. It must be a non-negative number. Received ' + n + '.');\n }\n this._maxListeners = n;\n return this;\n};\n\nfunction $getMaxListeners(that) {\n if (that._maxListeners === undefined)\n return EventEmitter.defaultMaxListeners;\n return that._maxListeners;\n}\n\nEventEmitter.prototype.getMaxListeners = function getMaxListeners() {\n return $getMaxListeners(this);\n};\n\nEventEmitter.prototype.emit = function emit(type) {\n var args = [];\n for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);\n var doError = (type === 'error');\n\n var events = this._events;\n if (events !== undefined)\n doError = (doError && events.error === undefined);\n else if (!doError)\n return false;\n\n // If there is no 'error' event listener then throw.\n if (doError) {\n var er;\n if (args.length > 0)\n er = args[0];\n if (er instanceof Error) {\n // Note: The comments on the `throw` lines are intentional, they show\n // up in Node's output if this results in an unhandled exception.\n throw er; // Unhandled 'error' event\n }\n // At least give some kind of context to the user\n var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));\n err.context = er;\n throw err; // Unhandled 'error' event\n }\n\n var handler = events[type];\n\n if (handler === undefined)\n return false;\n\n if (typeof handler === 'function') {\n ReflectApply(handler, this, args);\n } else {\n var len = handler.length;\n var listeners = arrayClone(handler, len);\n for (var i = 0; i < len; ++i)\n ReflectApply(listeners[i], this, args);\n }\n\n return true;\n};\n\nfunction _addListener(target, type, listener, prepend) {\n var m;\n var events;\n var existing;\n\n if (typeof listener !== 'function') {\n throw new TypeError('The \"listener\" argument must be of type Function. Received type ' + typeof listener);\n }\n\n events = target._events;\n if (events === undefined) {\n events = target._events = Object.create(null);\n target._eventsCount = 0;\n } else {\n // To avoid recursion in the case that type === \"newListener\"! Before\n // adding it to the listeners, first emit \"newListener\".\n if (events.newListener !== undefined) {\n target.emit('newListener', type,\n listener.listener ? listener.listener : listener);\n\n // Re-assign `events` because a newListener handler could have caused the\n // this._events to be assigned to a new object\n events = target._events;\n }\n existing = events[type];\n }\n\n if (existing === undefined) {\n // Optimize the case of one listener. Don't need the extra array object.\n existing = events[type] = listener;\n ++target._eventsCount;\n } else {\n if (typeof existing === 'function') {\n // Adding the second element, need to change to array.\n existing = events[type] =\n prepend ? [listener, existing] : [existing, listener];\n // If we've already got an array, just append.\n } else if (prepend) {\n existing.unshift(listener);\n } else {\n existing.push(listener);\n }\n\n // Check for listener leak\n m = $getMaxListeners(target);\n if (m > 0 && existing.length > m && !existing.warned) {\n existing.warned = true;\n // No error code for this since it is a Warning\n // eslint-disable-next-line no-restricted-syntax\n var w = new Error('Possible EventEmitter memory leak detected. ' +\n existing.length + ' ' + String(type) + ' listeners ' +\n 'added. Use emitter.setMaxListeners() to ' +\n 'increase limit');\n w.name = 'MaxListenersExceededWarning';\n w.emitter = target;\n w.type = type;\n w.count = existing.length;\n ProcessEmitWarning(w);\n }\n }\n\n return target;\n}\n\nEventEmitter.prototype.addListener = function addListener(type, listener) {\n return _addListener(this, type, listener, false);\n};\n\nEventEmitter.prototype.on = EventEmitter.prototype.addListener;\n\nEventEmitter.prototype.prependListener =\n function prependListener(type, listener) {\n return _addListener(this, type, listener, true);\n };\n\nfunction onceWrapper() {\n var args = [];\n for (var i = 0; i < arguments.length; i++) args.push(arguments[i]);\n if (!this.fired) {\n this.target.removeListener(this.type, this.wrapFn);\n this.fired = true;\n ReflectApply(this.listener, this.target, args);\n }\n}\n\nfunction _onceWrap(target, type, listener) {\n var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };\n var wrapped = onceWrapper.bind(state);\n wrapped.listener = listener;\n state.wrapFn = wrapped;\n return wrapped;\n}\n\nEventEmitter.prototype.once = function once(type, listener) {\n if (typeof listener !== 'function') {\n throw new TypeError('The \"listener\" argument must be of type Function. Received type ' + typeof listener);\n }\n this.on(type, _onceWrap(this, type, listener));\n return this;\n};\n\nEventEmitter.prototype.prependOnceListener =\n function prependOnceListener(type, listener) {\n if (typeof listener !== 'function') {\n throw new TypeError('The \"listener\" argument must be of type Function. Received type ' + typeof listener);\n }\n this.prependListener(type, _onceWrap(this, type, listener));\n return this;\n };\n\n// Emits a 'removeListener' event if and only if the listener was removed.\nEventEmitter.prototype.removeListener =\n function removeListener(type, listener) {\n var list, events, position, i, originalListener;\n\n if (typeof listener !== 'function') {\n throw new TypeError('The \"listener\" argument must be of type Function. Received type ' + typeof listener);\n }\n\n events = this._events;\n if (events === undefined)\n return this;\n\n list = events[type];\n if (list === undefined)\n return this;\n\n if (list === listener || list.listener === listener) {\n if (--this._eventsCount === 0)\n this._events = Object.create(null);\n else {\n delete events[type];\n if (events.removeListener)\n this.emit('removeListener', type, list.listener || listener);\n }\n } else if (typeof list !== 'function') {\n position = -1;\n\n for (i = list.length - 1; i >= 0; i--) {\n if (list[i] === listener || list[i].listener === listener) {\n originalListener = list[i].listener;\n position = i;\n break;\n }\n }\n\n if (position < 0)\n return this;\n\n if (position === 0)\n list.shift();\n else {\n spliceOne(list, position);\n }\n\n if (list.length === 1)\n events[type] = list[0];\n\n if (events.removeListener !== undefined)\n this.emit('removeListener', type, originalListener || listener);\n }\n\n return this;\n };\n\nEventEmitter.prototype.off = EventEmitter.prototype.removeListener;\n\nEventEmitter.prototype.removeAllListeners =\n function removeAllListeners(type) {\n var listeners, events, i;\n\n events = this._events;\n if (events === undefined)\n return this;\n\n // not listening for removeListener, no need to emit\n if (events.removeListener === undefined) {\n if (arguments.length === 0) {\n this._events = Object.create(null);\n this._eventsCount = 0;\n } else if (events[type] !== undefined) {\n if (--this._eventsCount === 0)\n this._events = Object.create(null);\n else\n delete events[type];\n }\n return this;\n }\n\n // emit removeListener for all listeners on all events\n if (arguments.length === 0) {\n var keys = Object.keys(events);\n var key;\n for (i = 0; i < keys.length; ++i) {\n key = keys[i];\n if (key === 'removeListener') continue;\n this.removeAllListeners(key);\n }\n this.removeAllListeners('removeListener');\n this._events = Object.create(null);\n this._eventsCount = 0;\n return this;\n }\n\n listeners = events[type];\n\n if (typeof listeners === 'function') {\n this.removeListener(type, listeners);\n } else if (listeners !== undefined) {\n // LIFO order\n for (i = listeners.length - 1; i >= 0; i--) {\n this.removeListener(type, listeners[i]);\n }\n }\n\n return this;\n };\n\nfunction _listeners(target, type, unwrap) {\n var events = target._events;\n\n if (events === undefined)\n return [];\n\n var evlistener = events[type];\n if (evlistener === undefined)\n return [];\n\n if (typeof evlistener === 'function')\n return unwrap ? [evlistener.listener || evlistener] : [evlistener];\n\n return unwrap ?\n unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);\n}\n\nEventEmitter.prototype.listeners = function listeners(type) {\n return _listeners(this, type, true);\n};\n\nEventEmitter.prototype.rawListeners = function rawListeners(type) {\n return _listeners(this, type, false);\n};\n\nEventEmitter.listenerCount = function(emitter, type) {\n if (typeof emitter.listenerCount === 'function') {\n return emitter.listenerCount(type);\n } else {\n return listenerCount.call(emitter, type);\n }\n};\n\nEventEmitter.prototype.listenerCount = listenerCount;\nfunction listenerCount(type) {\n var events = this._events;\n\n if (events !== undefined) {\n var evlistener = events[type];\n\n if (typeof evlistener === 'function') {\n return 1;\n } else if (evlistener !== undefined) {\n return evlistener.length;\n }\n }\n\n return 0;\n}\n\nEventEmitter.prototype.eventNames = function eventNames() {\n return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];\n};\n\nfunction arrayClone(arr, n) {\n var copy = new Array(n);\n for (var i = 0; i < n; ++i)\n copy[i] = arr[i];\n return copy;\n}\n\nfunction spliceOne(list, index) {\n for (; index + 1 < list.length; index++)\n list[index] = list[index + 1];\n list.pop();\n}\n\nfunction unwrapListeners(arr) {\n var ret = new Array(arr.length);\n for (var i = 0; i < ret.length; ++i) {\n ret[i] = arr[i].listener || arr[i];\n }\n return ret;\n}\n","\nconst OperationEvent = {\n START: 'start',\n READY: 'ready',\n DONE: 'done',\n CANCEL: 'cancel',\n ERROR: 'e'\n}\n\nmodule.exports = {\n OperationEvent\n}","const EventEmitter = require('events')\nconst { CircularOperationValidator } = require('./CircularOperationValidator');\nconst { QueuePriority } = require('./QueuePriority');\nconst { QueueEvent } = require('./QueueEvent');\n\nclass OperationQueue {\n\n constructor() {\n this.ee = new EventEmitter();\n this.time = {};\n this.map = {};\n this.operations = [];\n this._processedOperations = [];\n this.resolve = null;\n this.completionCallback = null;\n this.maximumConcurentOperations = 10;\n\n this.readyQueueMap = {};\n this.readyQueue = [];\n\n this.runningQueueMap = {};\n this.runningQueue = [];\n\n this.queues = {\n [QueuePriority.veryHigh]: [],\n [QueuePriority.high]: [],\n [QueuePriority.normal]: [],\n [QueuePriority.low]: [],\n [QueuePriority.veryLow]: []\n }\n\n this._isDone = false;\n }\n \n on(event, cb) {\n this.ee.on(event, cb);\n }\n\n off(event, cb) {\n this.ee.off(event, cb);\n }\n\n get totalTime() {\n return Math.abs((this.time.start.getTime() - this.time.end.getTime()) / 1000);\n }\n\n get isExecuting() {\n return !this._isEmpty(this.map);\n }\n\n done() {\n if (this._isDone) {\n return;\n }\n \n this.time.end = new Date();\n this._isDone = true;\n this.completionCallback && this.completionCallback();\n this.resolve();\n }\n\n /**\n * \n * @param {Operation} operation \n */\n addOperation(operation) {\n this.addOperations([operation]);\n }\n\n /**\n * \n * @param {Array.} operations\n */\n addOperations(operations) {\n this.operations = this.operations.concat(operations);\n this._preProcessOperations(operations);\n this._processedOperations = this._processedOperations.concat(this.operations);\n this._begin();\n }\n\n pause() {\n this._paused = true;\n }\n\n resume() {\n this._paused = false;\n this._checkNextOperation();\n }\n\n get isPaused() {\n return this._paused;\n }\n\n _preProcessOperations(operations) {\n operations.forEach(op => {\n if (!this.map[op.id]) {\n this.map[op.id] = true;\n op.isInQueue = true;\n this._bindOperation(op);\n };\n this._preProcessOperations(op.dependencies);\n });\n }\n\n _bindOperation(operation) {\n operation.on('start', this._onOperationStart.bind(this));\n operation.on('ready', this._onOperationReady.bind(this));\n operation.on('cancel', this._onOperationCancel.bind(this));\n operation.on('done', this._onOperationDone.bind(this));\n }\n\n _unbindOperation(operation) {\n operation.off('start', this._onOperationStart.bind(this));\n operation.off('ready', this._onOperationReady.bind(this));\n operation.off('cancel', this._onOperationCancel.bind(this));\n operation.off('done', this._onOperationDone.bind(this));\n }\n\n _begin() {\n if (this.promise) {\n this._startOperations();\n } else {\n this.promise = new Promise((resolve, reject) => {\n try {\n new CircularOperationValidator(this._processedOperations);\n } catch (e) {\n return reject(e);\n }\n this.time.start = new Date();\n this.resolve = resolve;\n \n this._startOperations();\n });\n }\n }\n\n _startOperations() {\n this._processedOperations.forEach(operation => {\n this._startOperation(operation);\n });\n }\n\n _startOperation(operation) {\n operation.start();\n }\n\n _onOperationStart(operation) {\n //\n }\n\n _onOperationReady(operation) {\n if (this.readyQueueMap[operation.id]) {\n return;\n }\n this.readyQueueMap[operation.id] = true;\n this.queues[operation.queuePriority].push(operation);\n\n this._checkNextOperation() \n }\n\n _onOperationDone(operation) {\n this._unbindOperation(operation);\n\n this.runningQueue = this.runningQueue.filter(op => op.id !== operation.id);\n \n delete this.map[operation.id];\n delete this.runningQueueMap[operation.id];\n \n if (this._isEmpty(this.map)) {\n this.ee.emit(QueueEvent.DONE, this);\n this.done();\n } else {\n this._checkNextOperation();\n }\n }\n\n _checkNextOperation() {\n if (this._paused) {\n return;\n }\n\n if (this.runningQueue.length < this.maximumConcurentOperations && this._hasOperations()) {\n const operation = this._getNextOperation();\n if (!operation.isExecuting || !operation.isCancelled || !this.runningQueueMap[operation.id]) {\n this.runningQueueMap[operation.id] = true;\n this.runningQueue.push(operation);\n operation.main();\n this._checkNextOperation()\n }\n }\n }\n\n _hasOperations() {\n return !!(this.queues[QueuePriority.veryHigh].length\n + this.queues[QueuePriority.high].length\n + this.queues[QueuePriority.normal].length\n + this.queues[QueuePriority.low].length\n + this.queues[QueuePriority.veryLow].length);\n }\n\n _getNextOperation() {\n if (this.queues[QueuePriority.veryHigh].length) {\n return this.queues[QueuePriority.veryHigh].pop();\n } else if (this.queues[QueuePriority.high].length) {\n return this.queues[QueuePriority.high].pop();\n } else if (this.queues[QueuePriority.normal].length) {\n return this.queues[QueuePriority.normal].pop();\n } else if (this.queues[QueuePriority.low].length) {\n return this.queues[QueuePriority.low].pop();\n } else if (this.queues[QueuePriority.veryLow].length) {\n return this.queues[QueuePriority.veryLow].pop();\n }\n }\n\n\n _onOperationCancel(operation) {\n delete this.map[operation.id];\n if (this._isEmpty(this.map)) {\n this.ee.emit(QueueEvent.DONE, this);\n this.done();\n }\n }\n\n _isEmpty(obj) {\n for(var key in obj) {\n if(obj.hasOwnProperty(key))\n return false;\n }\n return true;\n }\n}\n\nmodule.exports = {\n OperationQueue\n}","\nconst { Operation } = require('./Operation');\nconst { OperationQueue } = require('./OperationQueue');\nconst { BlockOperation } = require('./BlockOperation');\nconst { GroupOperation } = require('./GroupOperation');\nconst { OperationEvent } = require('./OperationEvent');\nconst { QueuePriority } = require('./QueuePriority');\n\nmodule.exports = {\n Operation,\n OperationQueue,\n BlockOperation,\n GroupOperation,\n OperationEvent,\n QueuePriority\n};","var rng = require('./lib/rng');\nvar bytesToUuid = require('./lib/bytesToUuid');\n\nfunction v4(options, buf, offset) {\n var i = buf && offset || 0;\n\n if (typeof(options) == 'string') {\n buf = options === 'binary' ? new Array(16) : null;\n options = null;\n }\n options = options || {};\n\n var rnds = options.random || (options.rng || rng)();\n\n // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n rnds[6] = (rnds[6] & 0x0f) | 0x40;\n rnds[8] = (rnds[8] & 0x3f) | 0x80;\n\n // Copy bytes to buffer, if provided\n if (buf) {\n for (var ii = 0; ii < 16; ++ii) {\n buf[i + ii] = rnds[ii];\n }\n }\n\n return buf || bytesToUuid(rnds);\n}\n\nmodule.exports = v4;\n","// Unique ID creation requires a high quality random # generator. In the\n// browser this is a little complicated due to unknown quality of Math.random()\n// and inconsistent support for the `crypto` API. We do the best we can via\n// feature-detection\n\n// getRandomValues needs to be invoked in a context where \"this\" is a Crypto\n// implementation. Also, find the complete implementation of crypto on IE11.\nvar getRandomValues = (typeof(crypto) != 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto)) ||\n (typeof(msCrypto) != 'undefined' && typeof window.msCrypto.getRandomValues == 'function' && msCrypto.getRandomValues.bind(msCrypto));\n\nif (getRandomValues) {\n // WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto\n var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef\n\n module.exports = function whatwgRNG() {\n getRandomValues(rnds8);\n return rnds8;\n };\n} else {\n // Math.random()-based (RNG)\n //\n // If all else fails, use Math.random(). It's fast, but is of unspecified\n // quality.\n var rnds = new Array(16);\n\n module.exports = function mathRNG() {\n for (var i = 0, r; i < 16; i++) {\n if ((i & 0x03) === 0) r = Math.random() * 0x100000000;\n rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;\n }\n\n return rnds;\n };\n}\n","/**\n * Convert array of 16 byte values to UUID string format of the form:\n * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n */\nvar byteToHex = [];\nfor (var i = 0; i < 256; ++i) {\n byteToHex[i] = (i + 0x100).toString(16).substr(1);\n}\n\nfunction bytesToUuid(buf, offset) {\n var i = offset || 0;\n var bth = byteToHex;\n // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4\n return ([bth[buf[i++]], bth[buf[i++]], \n\tbth[buf[i++]], bth[buf[i++]], '-',\n\tbth[buf[i++]], bth[buf[i++]], '-',\n\tbth[buf[i++]], bth[buf[i++]], '-',\n\tbth[buf[i++]], bth[buf[i++]], '-',\n\tbth[buf[i++]], bth[buf[i++]],\n\tbth[buf[i++]], bth[buf[i++]],\n\tbth[buf[i++]], bth[buf[i++]]]).join('');\n}\n\nmodule.exports = bytesToUuid;\n","const copyArray = array => {\n return array.map(object => Object.assign(Object.create(object), object))\n}\n\nconst copyObject = object => {\n return Object.assign(Object.create(object), object);\n}\n\nmodule.exports = {\n copyArray,\n copyObject\n}","\nclass CircularOperationValidatorError extends Error {\n constructor(message = 'Circular dependency') {\n super()\n this.message = message;\n }\n}\n\nclass CircularOperationValidator {\n\n constructor(operations) {\n this.operations = operations\n this._checkCircular();\n }\n\n _checkCircular() {\n this.operations.forEach(operation => {\n operation.dependencies.forEach(op => {\n let map = {};\n map[operation.id] = Object.keys(map).length;\n this._verifyOpMap(op, map); \n this._checkDependencies(op, map)\n });\n });\n }\n\n _checkDependencies(operation, mapHash) {\n operation.dependencies.forEach(op => {\n let map = JSON.parse(JSON.stringify(mapHash));\n this._verifyOpMap(op, map);\n this._checkDependencies(op, map)\n })\n }\n\n _verifyOpMap(op, map) {\n if (map[op.id] !== undefined) {\n this._throwError(op, map)\n }\n\n map[op.id] = Object.keys(map).length;\n }\n\n _throwError(op, map) {\n let keys = Object.keys(map);\n\n let values = {};\n for (let key in map) {\n const value = map[key];\n values[value] = key;\n }\n\n values = Object.values(values);\n values.push(op.id);\n throw new CircularOperationValidatorError(`Circular: ${values}`);\n }\n\n}\n\nmodule.exports = {\n CircularOperationValidator\n}","const QueueEvent = {\n START: 'start',\n DONE: 'done',\n PAUSED: 'paused',\n RESUMED: 'resumed'\n}\n\nmodule.exports = {\n QueueEvent\n}","const { Operation } = require('./Operation');\n\nclass BlockOperation extends Operation {\n\n constructor() {\n let id;\n let block;\n\n const first = arguments[0];\n if (typeof first === 'number') {\n id = first;\n const second = arguments[1];\n if (typeof second === 'function') {\n block = second;\n }\n } else if (typeof first === 'function') {\n block = first;\n } else {\n throw new Error('Wrong arguments passed: missing ID and/or function');\n }\n \n super(id);\n this.block = block;\n }\n\n run() {\n return this.block();\n }\n}\n\nmodule.exports = {\n BlockOperation\n}","const { Operation } = require('./Operation');\nconst { OperationQueue } = require('./OperationQueue');\n\nclass GroupOperation extends Operation {\n\n constructor() {\n super();\n this.queue = new OperationQueue(); \n this.operations = [];\n }\n\n /**\n * @override\n * \n * @returns {Promise}\n */\n async run() {\n await this.queue.addOperations(this.operations)\n\n return this.operations.reduce((accum, operation) => {\n accum.push(operation.result);\n return accum;\n }, []); \n }\n\n /**\n * @override\n */\n async start() {\n this.dependencies = [];\n return super.start();\n }\n\n /**\n * @param {Operation} operation \n */\n addOperation(operation) {\n this.operations.push(operation);\n this.dependencies = [];\n }\n\n /**\n * @param {Array.} operation \n */\n addOperations(operations) {\n this.operations = this.operations.concat(operations);\n this.dependencies = [];\n }\n}\n\nmodule.exports = {\n GroupOperation\n}"],"sourceRoot":""} \ No newline at end of file diff --git a/src/BlockOperation.js b/src/BlockOperation.js index 057a32b..0c808ab 100644 --- a/src/BlockOperation.js +++ b/src/BlockOperation.js @@ -15,6 +15,8 @@ class BlockOperation extends Operation { } } else if (typeof first === 'function') { block = first; + } else { + throw new Error('Wrong arguments passed: missing ID and/or function'); } super(id); diff --git a/tests/BlockOperation.spec.js b/tests/BlockOperation.spec.js index cee3db0..c73b231 100644 --- a/tests/BlockOperation.spec.js +++ b/tests/BlockOperation.spec.js @@ -61,6 +61,15 @@ describe('BlockOperation', () => { expect(operation.id).toEqual(1); expect(runFunction).toHaveBeenCalled(); }); + + test('it should throw error if no parameters are passed in', (done) => { + try { + const operation = new BlockOperation(); + fail('should have failed at this point'); + } catch (e) { + done(); + } + }); }); describe('function start', () => {