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.1 to 1.0.2

2

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

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

@@ -99,2 +99,9 @@ # Workers Javascript

// Cancel parent worker
const runMe = workers.create('cancel', (worker) => {
// never call
worker.pop();
});
runMe.cancel();
// Set errors

@@ -131,2 +138,3 @@ workers.create('error', (worker) => {

interval(time: `number = 1000`) : `currentWorker` | PARENT | Run nodes like run in setInterval | stop() : `currentWorker`, NODE, Stop interval
cancel() : `currentWorker` | PARENT | Cancel current instance and execute complete callback
getId() : `number` | NODE | Get id of current node worker

@@ -133,0 +141,0 @@ getStatus() : `string` | ALL | Get status of current worker

@@ -45,2 +45,3 @@ var Workers = function()

case $enum.TYPE.ROOT:
delete _engine.this.cancel;
delete _engine.this.getId;

@@ -63,2 +64,3 @@ delete _engine.this.timeout;

case $enum.TYPE.NODE:
delete _engine.this.cancel;
delete _engine.this.timeout;

@@ -140,2 +142,12 @@ delete _engine.this.interval;

this.cancel = function()
{
_engine.totalWorkers -= 1;
if (_engine.totalWorkers === 0) {
$execCompleteCallback();
}
_engine.this.removeWorker(true);
return _engine.this;
}
this.pop = function()

@@ -142,0 +154,0 @@ {

@@ -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.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;
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.cancel,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.cancel,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.cancel=function(){return s.totalWorkers-=1,0===s.totalWorkers&&n(),s.this.removeWorker(!0),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;
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