Socket
Socket
Sign inDemoInstall

callback-sequence

Package Overview
Dependencies
6
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.1.0

.eslintrc

54

index.js

@@ -1,31 +0,31 @@

var util = require('util');
var runTask = require('orchestrator/lib/runTask');
var noop = function () {};
module.exports = function (callbacks) {
if (!callbacks) {
callbacks = [];
}
if (!Array.isArray(callbacks)) {
callbacks = Array.prototype.slice.call(arguments);
}
callbacks = callbacks.filter(util.isFunction);
module.exports = sequence;
module.exports.run = run;
var maxLen = callbacks.length;
function sequence() {
var callbacks = [].concat.apply([], arguments);
return function (done) {
run(callbacks, done);
};
}
return function (done) {
done = done || function () {};
(function next(i) {
if (i >= maxLen) {
return done();
}
var cb = callbacks[i];
runTask(cb, function (err) {
if (err) {
return done(err);
}
next(++i);
});
}(0));
};
};
function run(callbacks, done) {
done = done || noop;
if (callbacks.length === 0) {
return done();
}
var cb = callbacks[0];
if (typeof cb === 'function') {
runTask(cb, next);
} else {
next(null);
}
function next(err) {
if (err) {
return done(err);
}
run(callbacks.slice(1), done);
}
}
{
"name": "callback-sequence",
"version": "1.0.0",
"version": "1.1.0",
"description": "Make a new callback to run input callbacks in sequence",
"main": "index.js",
"scripts": {
"test": "tap test/*.js"
"test": "eslint . && tap test/*.js"
},

@@ -30,4 +30,5 @@ "repository": {

"devDependencies": {
"eslint": "^1.1.0",
"tap": "^1.3.1"
}
}

@@ -36,17 +36,20 @@ # callback-sequence

## cb = sequence(callbacks)
## cb = sequence()
### callbacks
Each argument passed in could be a [gulp task callback](https://github.com/gulpjs/gulp/blob/master/docs/API.md#gulptaskname-deps-fn),
or an array containing such elements.
Type: `Array`
`sequence` will create a callback to run all those specified tasks in appearance order.
`cb` has signature `cb(done)`, and `done` is called after those tasks finish,
with an error object or `null`.
Each element in `callbacks` is a [gulp task callback](https://github.com/gulpjs/gulp/blob/master/docs/API.md#gulptaskname-deps-fn).
## sequence.run(callbacks, done)
### cb
### callbacks
Type: `Array`
Type: `Function`
An array of [gulp task callback](https://github.com/gulpjs/gulp/blob/master/docs/API.md#gulptaskname-deps-fn)s.
Receives a `done` callback, which can be used as a gulp task callback.
`done`, if specified, is called after all tasks finish,
with an error object or `null`.
`cb` will run `callbacks` in sequence.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc