diff --git a/README.md b/README.md index a8478cd..23fe527 100644 --- a/README.md +++ b/README.md @@ -19,13 +19,15 @@ ## Features (to be implemented) -What can should do: +- **Add new tasks to the worker.** Tasks contain a callback function and a metadata object. They are used for conditional templating. -- add new tasks to the worker (these tasks are used for conditional templating) -- sort the tasks and partition then into batches. -- define a trigger that starts processing the tasks -- hold a status, and a trigger that stops processing these tasks -- define a context where tasks or task batches are executed +- **Sort tasks by priority and partion them into batches.** + +- **Allow to define triggers that start or stop processing of tasks.** + +- **Provide the status of the process.** + +- **Allow to provide an exection context where a task or a task batch is processed.** ## Usage @@ -44,11 +46,11 @@ $ bower install --save oolymer/oo-worker Develop. ~~~ -$ npm install -$ bower install --force-latest -$ npm run build:node:watch -$ npm run test:node:watch -$ npm run browser +$ yarn install +$ yarn install:bower +$ yarn build +$ yarn test +$ yarn start ~~~ Semantic versions. diff --git a/demo/oo-worker.demo.html b/demo/oo-worker.demo.html index b226760..e613b3b 100644 --- a/demo/oo-worker.demo.html +++ b/demo/oo-worker.demo.html @@ -18,7 +18,7 @@ - + @@ -43,10 +43,10 @@ - + - + + + diff --git a/oo-worker-mixin.html b/oo-worker-mixin.html new file mode 100644 index 0000000..1b290c3 --- /dev/null +++ b/oo-worker-mixin.html @@ -0,0 +1,35 @@ + + + + + diff --git a/oo-worker.min.js b/oo-worker.min.js index ee3a4c2..721d9f6 100644 --- a/oo-worker.min.js +++ b/oo-worker.min.js @@ -5,7 +5,7 @@ "use strict";function TinyQueue(t,e){if(!(this instanceof TinyQueue))return new TinyQueue(t,e);if(this.data=t||[],this.length=this.data.length,this.compare=e||defaultCompare,this.length>0)for(var i=(this.length>>1)-1;i>=0;i--)this._down(i)}function defaultCompare(t,e){return te?1:0}module.exports=TinyQueue,module.exports.default=TinyQueue,TinyQueue.prototype={push:function(t){this.data.push(t),this.length++,this._up(this.length-1)},pop:function(){if(0!==this.length){var t=this.data[0];return this.length--,this.length>0&&(this.data[0]=this.data[this.length],this._down(0)),this.data.pop(),t}},peek:function(){return this.data[0]},_up:function(t){for(var e=this.data,i=this.compare,h=e[t];t>0;){var n=t-1>>1,a=e[n];if(i(h,a)>=0)break;e[t]=a,t=n}e[t]=h},_down:function(t){for(var e=this.data,i=this.compare,h=this.length>>1,n=e[t];t=0)break;e[t]=u,t=a}e[t]=n}}; },{}],3:[function(require,module,exports){ -"use strict";var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0});var tinyqueue_1=__importDefault(require("tinyqueue")),p_queue_1=__importDefault(require("p-queue")),Worker=function(){function t(t,e){void 0===t&&(t="default"),void 0===e&&(e={}),this._name=t,this._options=e,this._initTaskPriorityQueue(),this._initTaskBatchProcessor()}return t.prototype._initTaskPriorityQueue=function(){this._tasks=new tinyqueue_1.default,this._tasks.compare=this._options.comparator||function(){return 0}},t.prototype._initTaskBatchProcessor=function(){this._processor=new p_queue_1.default({concurrency:this._options.concurrency||1,autoStart:!1})},t.prototype.queueTask=function(t){this._tasks.push(t)},t.prototype.dequeueTask=function(){return this._tasks.pop()},t.prototype.peekTask=function(){return this._tasks.peek()},t.prototype.clearTasks=function(){this._tasks.data=[]},Object.defineProperty(t.prototype,"numOfTasks",{get:function(){return this._tasks.length},enumerable:!0,configurable:!0}),t.prototype.queueTasks=function(){for(var t=[],e=0;e0&&this.numOfTasks>0;)e.push(this.dequeueTask()),t-=1;return e},t.prototype.processTasks=function(){for(var t=[],e=0;e0&&this.numOfTasks>0;)e.push(this.dequeueTask()),t-=1;return e},t.prototype.processTasks=function(){for(var t=[],e=0;e