baby-workers
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "baby-workers", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Manage your functions asynchronously or as stack with baby-workers.", | ||
@@ -5,0 +5,0 @@ "main": "workers.min.js", |
@@ -85,3 +85,3 @@ var Workers = function() | ||
_engine.status = $enum.STATUS.WAITING; | ||
_engine.totalWorkers = 1; | ||
_engine.this.addWorker(); | ||
delete _engine.this.set; | ||
@@ -102,7 +102,3 @@ return _engine.this; | ||
time = (time == null || typeof(time) != 'number' ? 1 : time); | ||
_engine.this.addWorker(); | ||
setTimeout(function() { | ||
_engine.this.run(); | ||
_engine.this.removeWorker(false); | ||
}, time); | ||
setTimeout(_engine.this.run, time); | ||
delete _engine.this.timeout; | ||
@@ -136,5 +132,7 @@ return _engine.this; | ||
} | ||
if (_parent.stack.currentNode == 0) { | ||
_engine.totalWorkers -= 1; | ||
_engine.this.removeWorker(false); | ||
} | ||
return _engine.this; | ||
@@ -287,6 +285,6 @@ } | ||
for (var index in _engine.completeCallback) { | ||
if (typeof(_engine.completeCallback[index].removeAfterCall) == 'boolean' && _engine.completeCallback[index] == false) { | ||
if (typeof(_engine.completeCallback[index].removeAfterCall) == 'boolean' && _engine.completeCallback[index].removeAfterCall == false) { | ||
newList.push(_engine.completeCallback[index]); | ||
} | ||
_engine.completeCallback[index].callback(_engine.error); | ||
_engine.completeCallback[index].callback(_engine.error, _engine.fatalError); | ||
} | ||
@@ -293,0 +291,0 @@ _engine.completeCallback = newList; |
@@ -1,1 +0,1 @@ | ||
var Workers=function(){var t={NONE:null,TYPE:{ROOT:"root",PARENT:"parent",NODE:"node"},STATUS:{WAITING:"waiting",RUNNING:"running",FINISH:"finish"}};Object.values="function"!=typeof Object.values?function(t){return Object.keys(t).map(function(e){return t[e]})}:Object.values;var e=function(r){this.create=function(r,n,i){return void 0!==s.children[r]||void 0!==s.this[r]?null:(s.children[r]=new e(r),s.children[r].init(s.this,t.TYPE.PARENT),s.children[r].set(n,i),s.this[r]=s.children[r],s.this[r])},this.init=function(e,r,n){switch(s.parent=e,s.type=r,s.id=n,r){case t.TYPE.ROOT:delete s.this.getId,delete s.this.timeout,delete s.this.interval,delete s.this.run,delete s.this.stack,delete s.this.pop,delete s.this.set,delete s.this.parent,delete s.this.root,delete s.this.node;break;case t.TYPE.PARENT:delete s.this.getId,delete s.this.pop,delete s.this.root;break;case t.TYPE.NODE:delete s.this.timeout,delete s.this.interval,delete s.this.run,delete s.this.stack,delete s.this.node}return delete s.this.init,s.this},this.set=function(r,n){n=null==n||"object"!=typeof n||void 0==n[0]?[n]:Object.values(n);for(var a in n){var o=new e(s.name);o.init(s.this,t.TYPE.NODE,a),i.nodes.push(o),i.worker+=1}return i.data=n,i.callback=r,s.status=t.STATUS.WAITING,s.totalWorkers=1,delete s.this.set,s.this},this.stack=function(){return i.stack.status=!0,s.this.run(),delete s.this.stack,s.this},this.timeout=function(t){return t=null==t||"number"!=typeof t?1:t,s.this.addWorker(),setTimeout(function(){s.this.run(),s.this.removeWorker(!1)},t),delete s.this.timeout,s.this},this.interval=function(t){t=null==t||"number"!=typeof t?1e3:t,s.this.addWorker();var e=setInterval(s.this.run,t);return s.this.stop=function(){s.this.removeWorker(!1),clearInterval(e)},delete s.this.interval,s.this},this.run=function(){s.status=t.STATUS.RUNNING;for(var e in i.data)(!0!==i.stack.status||i.stack.isRunning!==t.STATUS.RUNNING&&i.stack.currentNode===parseInt(e))&&(i.nodes[e].addWorker(),i.stack.isRunning=t.STATUS.RUNNING,i.callback(i.nodes[e],i.data[e]));return 0==i.stack.currentNode&&(s.totalWorkers-=1),s.this},this.pop=function(){return s.totalWorkers-=1,0===s.totalWorkers&&n(),s.parent.removeWorker(!0),s.this},this.getName=function(){return s.name},this.getType=function(){return s.type},this.getId=function(){return s.id},this.getStatus=function(){return s.status},this.addWorker=function(){return s.totalWorkers+=1,null!==s.parent&&s.parent.addWorker(),s.this},this.removeWorker=function(e){return"boolean"==typeof e&&!0===e&&(i.worker-=1,s.status=t.STATUS.FINISH,!0===i.stack.status&&(i.stack.currentNode+=1,i.stack.isRunning=t.STATUS.WAITING,s.this.run())),s.totalWorkers-=1,0===s.totalWorkers&&n(),null!==s.parent&&s.parent.removeWorker(!1),s.this},this.complete=function(t,e){return 0===s.totalWorkers&&(t(s.error,s.fatalError),"boolean"!=typeof e||1==e)?s.this:(s.completeCallback.push({callback:t,removeAfterCall:e}),s.this)},this.error=function(t,e){return s.error=null===s.error?t:s.error,s.fatalError=null===s.fatalError?e:s.fatalError,null!==s.parent&&s.parent.error(t,e),s.this},this.save=function(t){return s.save=t,s.this},this._save=function(t){var e=s.parent;return null==e?e:e.save(t)},this.get=function(){return s.save},this._get=function(){var t=s.parent;return null==t?t:t.get()},this.root=function(){return s.parent},this.parent=function(e,r){return null==s.parent?null:(r=void 0==r?t.TYPE.PARENT:r,s.parent.getName()!==e||r!==t.NONE&&s.parent.getType()!==r?void 0===s.parent.parent?null:s.parent.parent(e,r):s.parent)},this.parentNode=function(e){return s.this.parent(e,t.TYPE.NODE)},this.node=function(t){return void 0==s.nodes[t]?null:s.nodes[t]};var n=function(){var t=[];for(var e in s.completeCallback)"boolean"==typeof s.completeCallback[e].removeAfterCall&&0==s.completeCallback[e]&&t.push(s.completeCallback[e]),s.completeCallback[e].callback(s.error);s.completeCallback=t},i={nodes:[],worker:0,data:[],callback:null,stack:{status:!1,currentNode:0,isRunning:t.STATUS.WAITING}},s={this:this,id:null,name:r,parent:null,status:t.NONE,type:t.NONE,save:null,error:null,fatalError:null,children:{},completeCallback:[],totalWorkers:0}};return new e("root").init(null,t.TYPE.ROOT)};module.exports=Workers; | ||
var Workers=function(){var t={NONE:null,TYPE:{ROOT:"root",PARENT:"parent",NODE:"node"},STATUS:{WAITING:"waiting",RUNNING:"running",FINISH:"finish"}};Object.values="function"!=typeof Object.values?function(t){return Object.keys(t).map(function(e){return t[e]})}:Object.values;var e=function(r){this.create=function(r,n,i){return void 0!==s.children[r]||void 0!==s.this[r]?null:(s.children[r]=new e(r),s.children[r].init(s.this,t.TYPE.PARENT),s.children[r].set(n,i),s.this[r]=s.children[r],s.this[r])},this.init=function(e,r,n){switch(s.parent=e,s.type=r,s.id=n,r){case t.TYPE.ROOT:delete s.this.getId,delete s.this.timeout,delete s.this.interval,delete s.this.run,delete s.this.stack,delete s.this.pop,delete s.this.set,delete s.this.parent,delete s.this.root,delete s.this.node;break;case t.TYPE.PARENT:delete s.this.getId,delete s.this.pop,delete s.this.root;break;case t.TYPE.NODE:delete s.this.timeout,delete s.this.interval,delete s.this.run,delete s.this.stack,delete s.this.node}return delete s.this.init,s.this},this.set=function(r,n){n=null==n||"object"!=typeof n||void 0==n[0]?[n]:Object.values(n);for(var a in n){var o=new e(s.name);o.init(s.this,t.TYPE.NODE,a),i.nodes.push(o),i.worker+=1}return i.data=n,i.callback=r,s.status=t.STATUS.WAITING,s.this.addWorker(),delete s.this.set,s.this},this.stack=function(){return i.stack.status=!0,s.this.run(),delete s.this.stack,s.this},this.timeout=function(t){return t=null==t||"number"!=typeof t?1:t,setTimeout(s.this.run,t),delete s.this.timeout,s.this},this.interval=function(t){t=null==t||"number"!=typeof t?1e3:t,s.this.addWorker();var e=setInterval(s.this.run,t);return s.this.stop=function(){s.this.removeWorker(!1),clearInterval(e)},delete s.this.interval,s.this},this.run=function(){s.status=t.STATUS.RUNNING;for(var e in i.data)(!0!==i.stack.status||i.stack.isRunning!==t.STATUS.RUNNING&&i.stack.currentNode===parseInt(e))&&(i.nodes[e].addWorker(),i.stack.isRunning=t.STATUS.RUNNING,i.callback(i.nodes[e],i.data[e]));return 0==i.stack.currentNode&&s.this.removeWorker(!1),s.this},this.pop=function(){return s.totalWorkers-=1,0===s.totalWorkers&&n(),s.parent.removeWorker(!0),s.this},this.getName=function(){return s.name},this.getType=function(){return s.type},this.getId=function(){return s.id},this.getStatus=function(){return s.status},this.addWorker=function(){return s.totalWorkers+=1,null!==s.parent&&s.parent.addWorker(),s.this},this.removeWorker=function(e){return"boolean"==typeof e&&!0===e&&(i.worker-=1,s.status=t.STATUS.FINISH,!0===i.stack.status&&(i.stack.currentNode+=1,i.stack.isRunning=t.STATUS.WAITING,s.this.run())),s.totalWorkers-=1,0===s.totalWorkers&&n(),null!==s.parent&&s.parent.removeWorker(!1),s.this},this.complete=function(t,e){return 0===s.totalWorkers&&(t(s.error,s.fatalError),"boolean"!=typeof e||1==e)?s.this:(s.completeCallback.push({callback:t,removeAfterCall:e}),s.this)},this.error=function(t,e){return s.error=null===s.error?t:s.error,s.fatalError=null===s.fatalError?e:s.fatalError,null!==s.parent&&s.parent.error(t,e),s.this},this.save=function(t){return s.save=t,s.this},this._save=function(t){var e=s.parent;return null==e?e:e.save(t)},this.get=function(){return s.save},this._get=function(){var t=s.parent;return null==t?t:t.get()},this.root=function(){return s.parent},this.parent=function(e,r){return null==s.parent?null:(r=void 0==r?t.TYPE.PARENT:r,s.parent.getName()!==e||r!==t.NONE&&s.parent.getType()!==r?void 0===s.parent.parent?null:s.parent.parent(e,r):s.parent)},this.parentNode=function(e){return s.this.parent(e,t.TYPE.NODE)},this.node=function(t){return void 0==s.nodes[t]?null:s.nodes[t]};var n=function(){var t=[];for(var e in s.completeCallback)"boolean"==typeof s.completeCallback[e].removeAfterCall&&0==s.completeCallback[e].removeAfterCall&&t.push(s.completeCallback[e]),s.completeCallback[e].callback(s.error,s.fatalError);s.completeCallback=t},i={nodes:[],worker:0,data:[],callback:null,stack:{status:!1,currentNode:0,isRunning:t.STATUS.WAITING}},s={this:this,id:null,name:r,parent:null,status:t.NONE,type:t.NONE,save:null,error:null,fatalError:null,children:{},completeCallback:[],totalWorkers:0}};return new e("root").init(null,t.TYPE.ROOT)};module.exports=Workers; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21249
288