New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 0.0.9 to 1.0.0

2

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

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

@@ -20,5 +20,5 @@ # Workers Javascript

// Basic worker
workers.create('basic', (worker, id) => {
workers.create('basic', (worker, elem) => {
setTimeout(() => {
console.log('basic =>', id);
console.log('basic =>', elem, ' - ', 'my id =>', worker.getId());
worker.pop();

@@ -32,5 +32,5 @@ }, (~~(Math.random() * 1000)));

// Stack worker
workers.create('stack', (worker, id) => {
workers.create('stack', (worker, elem) => {
setTimeout(() => {
console.log('stack =>', id);
console.log('stack =>', elem, ' - ', 'my id =>', worker.getId());
worker.pop();

@@ -44,5 +44,5 @@ }, (~~(Math.random() * 1000)));

// Basic worker without array
workers.create('simple', (worker, id) => {
workers.create('simple', (worker, elem) => {
setTimeout(() => {
console.log('simple =>', id);
console.log('simple =>', elem);
worker.pop();

@@ -133,2 +133,3 @@ }, (~~(Math.random() * 1000)));

interval(time: `number = 1000`) : `currentWorker` | PARENT | Run nodes like run in setInterval | stop() : `currentWorker`, NODE, Stop interval
getId() : `number` | NODE | Get id of current node worker
getStatus() : `string` | ALL | Get status of current worker

@@ -135,0 +136,0 @@ getName() : `string` | ALL | Get name of current worker

@@ -37,9 +37,11 @@ var Workers = function()

this.init = function(parent, type)
this.init = function(parent, type, id)
{
_engine.parent = parent;
_engine.type = type;
_engine.id = id;
switch (type)
{
case $enum.TYPE.ROOT:
delete _engine.this.getId;
delete _engine.this.timeout;

@@ -56,2 +58,3 @@ delete _engine.this.interval;

case $enum.TYPE.PARENT:
delete _engine.this.getId;
delete _engine.this.pop;

@@ -77,3 +80,3 @@ delete _engine.this.root;

var nodeProcess = new $process(_engine.name);
nodeProcess.init(_engine.this, $enum.TYPE.NODE);
nodeProcess.init(_engine.this, $enum.TYPE.NODE, index);
_parent.nodes.push(nodeProcess);

@@ -160,2 +163,7 @@ _parent.worker += 1;

this.getId = function()
{
return _engine.id;
}
this.getStatus = function()

@@ -302,2 +310,3 @@ {

this: this,
id: null,
name: processName,

@@ -304,0 +313,0 @@ parent: null,

@@ -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,s){return void 0!==a.children[r]||void 0!==a.this[r]?null:(a.children[r]=new e(r),a.children[r].init(a.this,t.TYPE.PARENT),a.children[r].set(n,s),a.this[r]=a.children[r],a.this[r])},this.init=function(e,r){switch(a.parent=e,a.type=r,r){case t.TYPE.ROOT:delete a.this.timeout,delete a.this.interval,delete a.this.run,delete a.this.stack,delete a.this.pop,delete a.this.set,delete a.this.parent,delete a.this.root,delete a.this.node;break;case t.TYPE.PARENT:delete a.this.pop,delete a.this.root;break;case t.TYPE.NODE:delete a.this.timeout,delete a.this.interval,delete a.this.run,delete a.this.stack,delete a.this.node}return delete a.this.init,a.this},this.set=function(r,n){n=null==n||"object"!=typeof n||void 0==n[0]?[n]:Object.values(n);for(var i in n){var o=new e(a.name);o.init(a.this,t.TYPE.NODE),s.nodes.push(o),s.worker+=1}return s.data=n,s.callback=r,a.status=t.STATUS.WAITING,a.totalWorkers=1,delete a.this.set,a.this},this.stack=function(){return s.stack.status=!0,a.this.run(),delete a.this.stack,a.this},this.timeout=function(t){return t=null==t||"number"!=typeof t?1:t,a.this.addWorker(),setTimeout(function(){a.this.run(),a.this.removeWorker(!1)},t),delete a.this.timeout,a.this},this.interval=function(t){t=null==t||"number"!=typeof t?1e3:t,a.this.addWorker();var e=setInterval(a.this.run,t);return a.this.stop=function(){a.this.removeWorker(!1),clearInterval(e)},delete a.this.interval,a.this},this.run=function(){a.status=t.STATUS.RUNNING;for(var e in s.data)(!0!==s.stack.status||s.stack.isRunning!==t.STATUS.RUNNING&&s.stack.currentNode===parseInt(e))&&(s.nodes[e].addWorker(),s.stack.isRunning=t.STATUS.RUNNING,s.callback(s.nodes[e],s.data[e]));return 0==s.stack.currentNode&&(a.totalWorkers-=1),a.this},this.pop=function(){return a.totalWorkers-=1,0===a.totalWorkers&&n(),a.parent.removeWorker(!0),a.this},this.getName=function(){return a.name},this.getType=function(){return a.type},this.getStatus=function(){return a.status},this.addWorker=function(){return a.totalWorkers+=1,null!==a.parent&&a.parent.addWorker(),a.this},this.removeWorker=function(e){return"boolean"==typeof e&&!0===e&&(s.worker-=1,a.status=t.STATUS.FINISH,!0===s.stack.status&&(s.stack.currentNode+=1,s.stack.isRunning=t.STATUS.WAITING,a.this.run())),a.totalWorkers-=1,0===a.totalWorkers&&n(),null!==a.parent&&a.parent.removeWorker(!1),a.this},this.complete=function(t,e){return 0===a.totalWorkers&&(t(a.error,a.fatalError),"boolean"!=typeof e||1==e)?a.this:(a.completeCallback.push({callback:t,removeAfterCall:e}),a.this)},this.error=function(t,e){return a.error=null===a.error?t:a.error,a.fatalError=null===a.fatalError?e:a.fatalError,null!==a.parent&&a.parent.error(t,e),a.this},this.save=function(t){return a.save=t,a.this},this._save=function(t){var e=a.parent;return null==e?e:e.save(t)},this.get=function(){return a.save},this._get=function(){var t=a.parent;return null==t?t:t.get()},this.root=function(){return a.parent},this.parent=function(e,r){return null==a.parent?null:(r=void 0==r?t.TYPE.PARENT:r,a.parent.getName()!==e||r!==t.NONE&&a.parent.getType()!==r?void 0===a.parent.parent?null:a.parent.parent(e,r):a.parent)},this.parentNode=function(e){return a.this.parent(e,t.TYPE.NODE)},this.node=function(t){return void 0==a.nodes[t]?null:a.nodes[t]};var n=function(){var t=[];for(var e in a.completeCallback)"boolean"==typeof a.completeCallback[e].removeAfterCall&&0==a.completeCallback[e]&&t.push(a.completeCallback[e]),a.completeCallback[e].callback(a.error);a.completeCallback=t},s={nodes:[],worker:0,data:[],callback:null,stack:{status:!1,currentNode:0,isRunning:t.STATUS.WAITING}},a={this:this,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.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;
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