Package Exports
- man
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (man) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
man
Node.js package. Provides a series of helper functions that allow you to perform asynchronous iteration and flow control.
Installation
npm install man
Callbacks aggregation
If you want to receive results of several callbacks at the same time, use callback()
method:
var fs = require('fs'),
man = require('man'),
cb = man.callback();
fs.readFile('file1.txt', cb.callback);
fs.readFile('file2.txt', cb.callback);
cb.on(function (err, content) {
// On each callback.
});
cb.done(function (result1, result2) {
// When all callbacks have received the results.
});
Serial execution
var man = require('man');
man.do(function () {
fs.readFile('file1.txt', this.next);
}).do(function (err, content) {
fs.readFile('file2.txt', this.next);
}).do(function (err, content) {
// ...
});
Parallel execution
var man = require('man');
man.doAsync(function () {
// ...
this.done(result1);
}).do(function () {
// ...
this.done(result2);
}).then(function (result1, result2) {
// ...
});
Iterations
Serial iterations
var man = require('man');
man.for([1, 2, 3, 4, 5]).do(function (number) {
// On each item.
this.done(number + 1);
}).then(function (results) {
// When all items have processed.
console.log(results); // [2, 3, 4, 5, 6]
});
Parallel iterations
var man = require('man');
man.forAsync([1, 2, 3, 4, 5]).do(function (number) {
// On each item.
this.done(number + 1);
}).then(function (results) {
// When all items have processed.
console.log(results); // [2, 3, 4, 5, 6]
});