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

putil-waterfall

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

putil-waterfall - npm Package Compare versions

Comparing version 1.0.8 to 1.1.0

72

lib/waterfall.js

@@ -17,4 +17,3 @@ /* putil-waterfall

callback = callback || function() {
};
callback = callback || function() {};

@@ -24,28 +23,28 @@ if (!funcs.length)

let index = -1;
var index = -1;
const next = function(error) {
if (error)
return callback(error);
function next(error, ...args) {
if (error) {
callback(error);
return;
}
const args = Array.prototype.slice.call(arguments, 1);
index++;
const fn = funcs[index];
if (fn) {
setImmediate(() => {
setImmediate(function() {
try {
const o = fn(next, ...args);
if (o && (o instanceof Promise ||
(typeof o.then === 'function' &&
typeof o.catch === 'function'))) {
o.catch(err => {
callback(err);
const o = fn.apply(fn, [next].concat(args));
// If promise
if (o && typeof o === 'object' &&
typeof o.then === 'function' && typeof o.catch === 'function') {
o.catch(function(e) {
callback.apply(callback, [e].concat(args));
});
}
} catch (e) {
callback(e);
callback.apply(callback, [e].concat(args));
}
});
} else callback(undefined, ...args);
}
} else
callback.apply(callback, [undefined].concat(args));
};

@@ -55,2 +54,39 @@ next(null);

waterfall.every = function(arr, fn, callback) {
if (callback && typeof callback !== 'function')
throw new Error('Invalid callback argument');
if (!Array.isArray(arr))
throw new Error('Invalid argument. Array value are required as first argument');
callback = callback || function() {};
var index = -1;
const next = function(error) {
if (error)
return callback(error);
if (!arr.length)
return callback();
const v = arr.shift();
const args = Array.prototype.slice.call(arguments, 1);
index++;
setImmediate(function() {
try {
const o = fn.apply(fn, [next, v, index].concat(args));
// If promise
if (o && typeof o === 'object' &&
typeof o.then === 'function' && typeof o.catch === 'function') {
o.catch(function(e) {
callback.apply(callback, [e, v, index].concat(args));
});
}
} catch (e) {
callback.apply(callback, [e, v, index].concat(args));
}
});
};
next(null);
};
module.exports = waterfall;
{
"name": "putil-waterfall",
"description": "Simple, fast async waterfall NodeJs module for ES6.",
"version": "1.0.8",
"version": "1.1.0",
"author": "Panates Ltd.",

@@ -23,2 +23,3 @@ "contributors": [

"babel-eslint": "^7.2.3",
"bluebird": "^3.5.0",
"eslint": "^3.19.0",

@@ -25,0 +26,0 @@ "eslint-config-google": "^0.8.0",

@@ -61,5 +61,31 @@ # putil-waterfall

`waterfall.every(array, fn, callback)`
**array:** Any array
**fn:** Function to be called for every value. `fn(next, value, index)
**callback:** An optional callback to run once iteration completed.
```javascript
const waterfall = require('putil-waterfall');
var total = 0;
waterfall.every([1, 2, 3, 4],
function(next, val) {
total += val;
next(null);
},
function(err) {
console.log('Total: ' + total);
});
```
Result output
```
Total: 10
```
## Node Compatibility
- node `>= 6.x`;
- node `>= 4.0`;

@@ -66,0 +92,0 @@ ### License

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