Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

baby-workers

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

baby-workers - npm Package Compare versions

Comparing version 1.0.7 to 1.0.71

2

package.json
{
"name": "baby-workers",
"version": "1.0.7",
"version": "1.0.71",
"description": "Manage your functions asynchronously or as stack with baby-workers.",

@@ -5,0 +5,0 @@ "main": "workers.min.js",

@@ -98,2 +98,3 @@ # Workers Javascript

getType() : `string` | ALL | Return type of current worker
getNodes() : `array` | PARENT | Return all nodes
getLimit() : `number` | ALL | Return the limit of workers allowed in current workers

@@ -100,0 +101,0 @@ getWorkers() : `number` | ALL | Return the number of workers

@@ -303,2 +303,7 @@ var Workers = function()

this.getNodes = function()
{
return _parent.nodes;
}
this.limit = function(max, extra)

@@ -452,3 +457,3 @@ {

{
return (_engine.nodes[key] == undefined ? null : _engine.nodes[key]);
return (_parent.nodes[key] == undefined ? null : _parent.nodes[key]);
}

@@ -536,2 +541,2 @@

module.exports = Workers;
module.exports = Workers;

@@ -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!==h.children[r]||void 0!==h.this[r]?null:(h.children[r]=new e(r),h.children[r].init(h.this,t.TYPE.PARENT),h.children[r].set(n,i),h.this[r]=h.children[r],h.this[r])},this.init=function(e,r,n){switch(h.parent=e,h.type=r,h.id=n,r){case t.TYPE.ROOT:delete h.this.push,delete h.this.cancel,delete h.this.getId,delete h.this.timeout,delete h.this.interval,delete h.this.run,delete h.this.stack,delete h.this.pop,delete h.this.set,delete h.this.parent,delete h.this.root,delete h.this.node;break;case t.TYPE.PARENT:delete h.this.getId,delete h.this.pop,delete h.this.root;break;case t.TYPE.NODE:delete h.this.push,delete h.this.cancel,delete h.this.timeout,delete h.this.interval,delete h.this.run,delete h.this.stack,delete h.this.node}return delete h.this.init,h.this},this.set=function(r,n){n=null===n&&void 0!==n?[]:0==Array.isArray(n)||void 0==n[0]?[n]:Object.values(n);for(var i in n){var s=new e(h.name);s.init(h.this,t.TYPE.NODE,i),u.nodes.push(s),u.workers+=1}return u.data=n,u.callback=r,h.status=t.STATUS.WAITING,h.this.addWorker(),delete h.this.set,h.this},this.stack=function(){return u.stack.status=!0,h.this.run(),delete h.this.stack,delete h.this.timeout,delete h.this.interval,h.this},this.timeout=function(t){return t=null==t||"number"!=typeof t?1:t,setTimeout(h.this.run,t),delete h.this.stack,delete h.this.timeout,delete h.this.interval,h.this},this.interval=function(t){return t=null==t||"number"!=typeof t?1e3:t,u.haveInterval=setInterval(h.this.run,t),h.this.stop=function(){h.this.removeWorker(!1),clearInterval(u.haveInterval)},delete h.this.stack,delete h.this.timeout,delete h.this.interval,h.this},this.run=function(){h.status=t.STATUS.RUNNING;for(var e in u.data)n(e);return null==u.haveInterval&&h.this.removeWorker(!1),0===u.runningWorkers&&0===u.waitingWorkers&&h.status===t.STATUS.RUNNING&&(h.status=t.STATUS.FINISH),delete h.this.stack,delete h.this.timeout,delete h.this.interval,h.this};var n=function(e){if(!0!==u.stack.status||u.stack.currentNode!==parseInt(e)||u.stack.isRunning!==t.STATUS.WAITING)if(!0!==u.stack.status)if(u.stack.currentNode>parseInt(e))h.this.waiting(s(e),!0,!0);else if(u.limitWorkers>0&&u.limitWorkers<=u.runningWorkers&&!1===u.limitExtra)h.this.waiting(s(e),!0,!0);else{var r=i();(0===u.limitWorkers||!0===u.limitExtra)&&null!=r&&r.getLimit()>0&&r.getLimit()<=r.getTotalRunningWorkers()+h.this.getRunningWorkers()&&r.getLimit()+(1==u.limitExtra?u.limitWorkers:0)<=r.getTotalRunningWorkers()+h.this.getRunningWorkers()?r.waiting(s(e),!0,!0):o(e)}else h.this.waiting(s(e),!0,!0);else o(e,!0)},i=function(t){return void 0===t&&null!=h.parent?i(h.parent):void 0!==t&&0===t.getLimit()&&"function"==typeof t.root?i(t.root()):t},s=function(t){return function(e){n(t),e()}},o=function(e,r){!1===r&&(u.stack.currentNode+=1),u.runningWorkers+=1,u.nodes[e].addWorker(!0),u.stack.isRunning=t.STATUS.RUNNING,u.callback(u.nodes[e],u.data[e])};this.push=function(r){if(null==r)return h.this;var i=u.data.push(r)-1,s=new e(h.name);return s.init(h.this,t.TYPE.NODE,i),u.nodes.push(s),u.workers+=1,h.status=t.STATUS.RUNNING,n(i),h.this},this.cancel=function(){return h.this.removeWorker(!0,!0),h.this},this.pop=function(){return h.totalWorkers-=1,0===h.totalWorkers&&0===h.totalWaitingWorkers&&l(),h.parent.removeWorker(!0,!0),h.this},this.getName=function(){return h.name},this.getType=function(){return h.type},this.getId=function(){return h.id},this.getStatus=function(){return h.status},this.getLimit=function(){return u.limitWorkers},this.getWorkers=function(){return u.workers},this.getWaitingWorkers=function(){return u.waitingWorkers},this.getRunningWorkers=function(){return u.runningWorkers},this.getTotalWorkers=function(){return h.totalWorkers},this.getTotalWaitingWorkers=function(){return h.totalWaitingWorkers},this.getTotalRunningWorkers=function(){return h.totalRunningWorkers},this.limit=function(t,e){return u.limitExtra="boolean"==typeof e&&!1!==e,u.limitWorkers=t<-1?-1:t,u.limitWorkers=!0===u.limitExtra&&-1===u.limitWorkers?0:u.limitWorkers,h.this},this.waiting=function(t,e,r){return h.totalWaitingWorkers+=1,"boolean"==typeof r&&!0===r&&(u.waitingWorkers+=1,h.waitingCallback.push({callback:function(e){u.waitingWorkers-=1,t(e)},removeAfterCall:e})),null!=h.parent?(h.parent.waiting(t,e,!1),h.this):h.this},this.complete=function(t,e){return 0===h.totalWorkers&&(t(h.error,h.fatalError),"boolean"!=typeof e||1==e)?h.this:(h.completeCallback.push({callback:t,removeAfterCall:e}),h.this)},this.addWorker=function(t){return"boolean"==typeof t&&!0===t&&(h.totalRunningWorkers+=1),h.totalWorkers+=1,null!==h.parent&&h.parent.addWorker(t),h.this},this.removeWorker=function(e,r){return"boolean"==typeof e&&!0===e&&(u.workers-=1,u.runningWorkers-=1,h.status=t.STATUS.FINISH,!0===u.stack.status&&(u.stack.currentNode+=1,u.stack.isRunning=t.STATUS.WAITING)),"boolean"==typeof r&&!0===r&&(h.totalRunningWorkers-=1),h.totalWorkers-=1,0!==u.waitingWorkers&&a(),0===h.totalWorkers&&0===h.totalWaitingWorkers&&l(),null!==h.parent&&h.parent.removeWorker(!1,r),h.this},this.error=function(t,e){return h.error=null===h.error?t:h.error,h.fatalError=null===h.fatalError?e:h.fatalError,null!==h.parent&&h.parent.error(t,e),h.this},this.save=function(t){return h.save=t,h.this},this._save=function(t){var e=h.parent;return null==e?e:e.save(t)},this.get=function(){return h.save},this._get=function(){var t=h.parent;return null==t?t:t.get()},this.root=function(){return h.parent},this.parent=function(e,r){return null==h.parent?null:(r=void 0==r?t.TYPE.PARENT:r,h.parent.getName()!==e||r!==t.NONE&&h.parent.getType()!==r?void 0===h.parent.parent?null:h.parent.parent(e,r):h.parent)},this.parentNode=function(e){return h.this.parent(e,t.TYPE.NODE)},this.node=function(t){return void 0==h.nodes[t]?null:h.nodes[t]},this.removeWaitingWorker=function(){return h.totalWaitingWorkers-=1,0===h.totalWorkers&&0===h.totalWaitingWorkers&&l(),null!=h.parent?(h.parent.removeWaitingWorker(),h.this):h.this};var a=function(){var t=h.waitingCallback;h.waitingCallback=[];for(var e in t)"boolean"==typeof t[e].removeAfterCall&&0==t[e].removeAfterCall&&h.waitingCallback.push(t[e]),t[e].callback(h.this.removeWaitingWorker)},l=function(){var t=h.completeCallback;h.completeCallback=[];for(var e in t)"boolean"==typeof t[e].removeAfterCall&&0==t[e].removeAfterCall&&h.completeCallback.push(t[e]),t[e].callback(h.error,h.fatalError)},u={limitWorkers:0,limitExtra:!1,wasRejected:!1,haveInterval:null,nodes:[],workers:0,runningWorkers:0,waitingWorkers:0,data:[],callback:null,stack:{status:!1,currentNode:0,isRunning:t.STATUS.WAITING}},h={this:this,id:null,name:r,parent:null,status:t.NONE,type:t.NONE,save:null,error:null,fatalError:null,children:{},completeCallback:[],waitingCallback:[],totalWorkers:0,totalRunningWorkers:0,totalWaitingWorkers: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!==h.children[r]||void 0!==h.this[r]?null:(h.children[r]=new e(r),h.children[r].init(h.this,t.TYPE.PARENT),h.children[r].set(n,i),h.this[r]=h.children[r],h.this[r])},this.init=function(e,r,n){switch(h.parent=e,h.type=r,h.id=n,r){case t.TYPE.ROOT:delete h.this.push,delete h.this.cancel,delete h.this.getId,delete h.this.timeout,delete h.this.interval,delete h.this.run,delete h.this.stack,delete h.this.pop,delete h.this.set,delete h.this.parent,delete h.this.root,delete h.this.node;break;case t.TYPE.PARENT:delete h.this.getId,delete h.this.pop,delete h.this.root;break;case t.TYPE.NODE:delete h.this.push,delete h.this.cancel,delete h.this.timeout,delete h.this.interval,delete h.this.run,delete h.this.stack,delete h.this.node}return delete h.this.init,h.this},this.set=function(r,n){n=null===n&&void 0!==n?[]:0==Array.isArray(n)||void 0==n[0]?[n]:Object.values(n);for(var i in n){var s=new e(h.name);s.init(h.this,t.TYPE.NODE,i),u.nodes.push(s),u.workers+=1}return u.data=n,u.callback=r,h.status=t.STATUS.WAITING,h.this.addWorker(),delete h.this.set,h.this},this.stack=function(){return u.stack.status=!0,h.this.run(),delete h.this.stack,delete h.this.timeout,delete h.this.interval,h.this},this.timeout=function(t){return t=null==t||"number"!=typeof t?1:t,setTimeout(h.this.run,t),delete h.this.stack,delete h.this.timeout,delete h.this.interval,h.this},this.interval=function(t){return t=null==t||"number"!=typeof t?1e3:t,u.haveInterval=setInterval(h.this.run,t),h.this.stop=function(){h.this.removeWorker(!1),clearInterval(u.haveInterval)},delete h.this.stack,delete h.this.timeout,delete h.this.interval,h.this},this.run=function(){h.status=t.STATUS.RUNNING;for(var e in u.data)n(e);return null==u.haveInterval&&h.this.removeWorker(!1),0===u.runningWorkers&&0===u.waitingWorkers&&h.status===t.STATUS.RUNNING&&(h.status=t.STATUS.FINISH),delete h.this.stack,delete h.this.timeout,delete h.this.interval,h.this};var n=function(e){if(!0!==u.stack.status||u.stack.currentNode!==parseInt(e)||u.stack.isRunning!==t.STATUS.WAITING)if(!0!==u.stack.status)if(u.stack.currentNode>parseInt(e))h.this.waiting(s(e),!0,!0);else if(u.limitWorkers>0&&u.limitWorkers<=u.runningWorkers&&!1===u.limitExtra)h.this.waiting(s(e),!0,!0);else{var r=i();(0===u.limitWorkers||!0===u.limitExtra)&&null!=r&&r.getLimit()>0&&r.getLimit()<=r.getTotalRunningWorkers()+h.this.getRunningWorkers()&&r.getLimit()+(1==u.limitExtra?u.limitWorkers:0)<=r.getTotalRunningWorkers()+h.this.getRunningWorkers()?r.waiting(s(e),!0,!0):o(e)}else h.this.waiting(s(e),!0,!0);else o(e,!0)},i=function(t){return void 0===t&&null!=h.parent?i(h.parent):void 0!==t&&0===t.getLimit()&&"function"==typeof t.root?i(t.root()):t},s=function(t){return function(e){n(t),e()}},o=function(e,r){!1===r&&(u.stack.currentNode+=1),u.runningWorkers+=1,u.nodes[e].addWorker(!0),u.stack.isRunning=t.STATUS.RUNNING,u.callback(u.nodes[e],u.data[e])};this.push=function(r){if(null==r)return h.this;var i=u.data.push(r)-1,s=new e(h.name);return s.init(h.this,t.TYPE.NODE,i),u.nodes.push(s),u.workers+=1,h.status=t.STATUS.RUNNING,n(i),h.this},this.cancel=function(){return h.this.removeWorker(!0,!0),h.this},this.pop=function(){return h.totalWorkers-=1,0===h.totalWorkers&&0===h.totalWaitingWorkers&&l(),h.parent.removeWorker(!0,!0),h.this},this.getName=function(){return h.name},this.getType=function(){return h.type},this.getId=function(){return h.id},this.getStatus=function(){return h.status},this.getLimit=function(){return u.limitWorkers},this.getWorkers=function(){return u.workers},this.getWaitingWorkers=function(){return u.waitingWorkers},this.getRunningWorkers=function(){return u.runningWorkers},this.getTotalWorkers=function(){return h.totalWorkers},this.getTotalWaitingWorkers=function(){return h.totalWaitingWorkers},this.getTotalRunningWorkers=function(){return h.totalRunningWorkers},this.getNodes=function(){return u.nodes},this.limit=function(t,e){return u.limitExtra="boolean"==typeof e&&!1!==e,u.limitWorkers=t<-1?-1:t,u.limitWorkers=!0===u.limitExtra&&-1===u.limitWorkers?0:u.limitWorkers,h.this},this.waiting=function(t,e,r){return h.totalWaitingWorkers+=1,"boolean"==typeof r&&!0===r&&(u.waitingWorkers+=1,h.waitingCallback.push({callback:function(e){u.waitingWorkers-=1,t(e)},removeAfterCall:e})),null!=h.parent?(h.parent.waiting(t,e,!1),h.this):h.this},this.complete=function(t,e){return 0===h.totalWorkers&&(t(h.error,h.fatalError),"boolean"!=typeof e||1==e)?h.this:(h.completeCallback.push({callback:t,removeAfterCall:e}),h.this)},this.addWorker=function(t){return"boolean"==typeof t&&!0===t&&(h.totalRunningWorkers+=1),h.totalWorkers+=1,null!==h.parent&&h.parent.addWorker(t),h.this},this.removeWorker=function(e,r){return"boolean"==typeof e&&!0===e&&(u.workers-=1,u.runningWorkers-=1,h.status=t.STATUS.FINISH,!0===u.stack.status&&(u.stack.currentNode+=1,u.stack.isRunning=t.STATUS.WAITING)),"boolean"==typeof r&&!0===r&&(h.totalRunningWorkers-=1),h.totalWorkers-=1,0!==u.waitingWorkers&&a(),0===h.totalWorkers&&0===h.totalWaitingWorkers&&l(),null!==h.parent&&h.parent.removeWorker(!1,r),h.this},this.error=function(t,e){return h.error=null===h.error?t:h.error,h.fatalError=null===h.fatalError?e:h.fatalError,null!==h.parent&&h.parent.error(t,e),h.this},this.save=function(t){return h.save=t,h.this},this._save=function(t){var e=h.parent;return null==e?e:e.save(t)},this.get=function(){return h.save},this._get=function(){var t=h.parent;return null==t?t:t.get()},this.root=function(){return h.parent},this.parent=function(e,r){return null==h.parent?null:(r=void 0==r?t.TYPE.PARENT:r,h.parent.getName()!==e||r!==t.NONE&&h.parent.getType()!==r?void 0===h.parent.parent?null:h.parent.parent(e,r):h.parent)},this.parentNode=function(e){return h.this.parent(e,t.TYPE.NODE)},this.node=function(t){return void 0==u.nodes[t]?null:u.nodes[t]},this.removeWaitingWorker=function(){return h.totalWaitingWorkers-=1,0===h.totalWorkers&&0===h.totalWaitingWorkers&&l(),null!=h.parent?(h.parent.removeWaitingWorker(),h.this):h.this};var a=function(){var t=h.waitingCallback;h.waitingCallback=[];for(var e in t)"boolean"==typeof t[e].removeAfterCall&&0==t[e].removeAfterCall&&h.waitingCallback.push(t[e]),t[e].callback(h.this.removeWaitingWorker)},l=function(){var t=h.completeCallback;h.completeCallback=[];for(var e in t)"boolean"==typeof t[e].removeAfterCall&&0==t[e].removeAfterCall&&h.completeCallback.push(t[e]),t[e].callback(h.error,h.fatalError)},u={limitWorkers:0,limitExtra:!1,wasRejected:!1,haveInterval:null,nodes:[],workers:0,runningWorkers:0,waitingWorkers:0,data:[],callback:null,stack:{status:!1,currentNode:0,isRunning:t.STATUS.WAITING}},h={this:this,id:null,name:r,parent:null,status:t.NONE,type:t.NONE,save:null,error:null,fatalError:null,children:{},completeCallback:[],waitingCallback:[],totalWorkers:0,totalRunningWorkers:0,totalWaitingWorkers:0}};return new e("root").init(null,t.TYPE.ROOT)};module.exports=Workers;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc