Socket
Socket
Sign inDemoInstall

twostep

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.1 to 0.3.2

.gitignore

94

lib/twoStep.js
module.exports = TwoStep;
module.exports.Steppy = Steppy;
var slice = Array.prototype.slice;
function Group(callback) {
/**
* Group represents one step in Step's execution flow. Makes a decision when
* the execution should jump to the next step.
*
* @param {function(err, args)} callback
* Callback to be called on successful execution end
* @param {function(err, args)} [errorCallback]
* If defined, will be called in case of error (default value: callback arg)
*/
function Group(callback, errorCallback) {
this.args = [null];
this.left = 0;
this.callback = callback;
this.errorCallback = errorCallback || callback;
this.isDone = false;

@@ -28,4 +40,3 @@ }

this.isDone = true;
var callback = this.callback;
callback(err);
this.errorCallback(err);
};

@@ -78,5 +89,21 @@

// Expose just for fun and extensibility
TwoStep.Group = Group;
/**
* TwoStep section
*/
// Execute steps immediately
function TwoStep() {
exec(slice.call(arguments), []);
}
// Create a composite function with steps built-in
TwoStep.fn = function () {
var steps = slice.call(arguments);
return function () {
var args = slice.call(arguments);
var callback = args.pop();
exec(steps, args, callback);
};
};
// Stepper function

@@ -105,17 +132,5 @@ function exec(steps, args, callback) {

// Execute steps immedietly
function TwoStep() {
exec(slice.call(arguments), []);
}
// Expose just for fun and extensibility
TwoStep.Group = Group;
// Create a composite function with steps built-in
TwoStep.fn = function () {
var steps = slice.call(arguments);
return function () {
var args = slice.call(arguments);
var callback = args.pop();
exec(steps, args, callback);
};
};
//Simple step function, just return callack

@@ -135,1 +150,42 @@ TwoStep.simple = function(callback) {

};
/**
* Steppy section
*/
// Execute steps immediately
function Steppy() {
execSteppy(slice.call(arguments), []);
}
// Stepper function
function execSteppy(steps, args, callback) {
if (steps.length < 2) {
throw new Error('Actually, you don\'t want to run less than two steps');
}
var pos = 0;
var errorHandler = steps[steps.length - 1];
function next() {
var step = steps[pos++];
if (!step) {
callback && callback.apply(null, arguments);
return;
}
var group = new Group(next, errorHandler);
try {
step.apply(group, arguments);
} catch (e) {
group.error(e);
return;
}
if (group.left === 0) {
group.done();
}
};
next.apply(null, args);
}
// Expose just for fun and extensibility
Steppy.Group = Group;
{
"name": "twostep",
"version": "0.3.1",
"version": "0.3.2",
"description": "A simple control-flow library for node.JS that makes parallel execution, serial execution, and error handling painless.",

@@ -5,0 +5,0 @@ "engine": [ "node >=0.2.0" ],

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