Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

serially

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

serially - npm Package Compare versions

Comparing version
1.1.0
to
2.0.0
x

Sorry, the diff of this file is not supported yet

+16
A="$1"
echo '{
"name": "'"$A"'",
"version": "2.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}' > package.json
npm publish
+5
-24
{
"name": "serially",
"version": "1.1.0",
"description": "Compose async functions into one function that runs all serially",
"version": "2.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "node test"
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"prova": "*",
"measure-time": "0.0.1"
},
"keywords": [
"serial",
"series",
"async",
"flow",
"flow control",
"serially"
],
"repository": {
"url": "git@github.com:azer/serially.git",
"type": "git"
},
"author": "azer",
"license": "BSD",
"dependencies": {
"serial-loop": "0.0.0"
}
"author": "",
"license": "ISC"
}

Sorry, the diff of this file is not supported yet

var loop = require("serial-loop");
module.exports = serially;
function serially (options) {
options || (options = {});
var fns = [];
var self = {
then: then,
run: then,
done: call,
end: call
};
return self;
function then (alias, fn, params) {
if (typeof alias != 'string') {
params = fn;
fn = alias;
alias = fn && fn.name;
}
if (typeof fn == 'undefined') {
throw new Error('serially: Undefined function given');
}
fns.push({ alias: alias, fn: fn, params: params });
return self;
}
function call (callback) {
var results = {};
var len = fns.length;
(function next (i, error) {
if (error) return callback(error, results);
if (i >= len) return callback(undefined, results);
var params = fns[i].params;
if (!params) {
params = [];
} else {
params = params.slice();
}
params.push(function (error) {
if (error) return next(i + 1, error);
results[fns[i].alias] = Array.prototype.slice.call(arguments, 1);
next(i+1);
});
fns[i].fn.apply(options.context, params);
}(0));
}
}
var time = require("measure-time");
var serially = require("./");
time('basic', function (end) {
serially()
.then(quux)
.then(corge)
.then(span)
.done(end);
});
time('with parameters and aliases', function (end) {
serially()
.then(foo, ['hello', 'world', '!'])
.then('bar-alias', bar, [1, 2, 3])
.then(qux, [4, 5, 6])
.done(end);
});
function foo (pa, ra, ms, callback) {
setImmediate(function () {
callback(undefined, pa + '\n' + ra + '\n' + ms);
});
}
function bar (pa, ra, ms, callback) {
setImmediate(function () {
callback(undefined, pa + ra + ms);
});
}
function qux (pa, ra, ms, callback) {
setImmediate(function () {
callback(undefined, pa * ra * ms);
});
}
function quux (callback) {
setImmediate(function () {
callback();
});
}
function corge (callback) {
setImmediate(function () {
callback();
});
}
function span (callback) {
setImmediate(function () {
callback();
});
}
## serially
Compose async functions into one function that runs all serially
See also: [parallelly](http://github.com/azer/parallelly)
## Install
```bash
$ npm install serially
```
## Usage
```js
var serially = require('serially')
var http = require('http')
var fs = require('fs')
serially()
.then(foo, ['a', 'b', 'c'])
.then(bar, [1, 2, 3])
.then('qux alias', qux, [4, 5, 6])
.done(function (error, results) {
if (error) throw error
console.log('done')
console.log(results)
// => { foo: [...], bar: [...], qux alias: [...] }
})
function foo (pa, ra, ms, callback) {}
function bar (pa, ra, ms, callback) {}
function qux (pa, ra, ms, callback) {}
```
See `test.js` for more info.