|
|
|
|
|
by apeace
3748 days ago
|
|
I find the `async` library excels at this: var fs = require('fs');
var async = require('async');
async.waterfall([
(cb) => fs.readFile('foo.txt', cb),
(data, cb) => my_function(data, cb),
(result, cb) => myDb.lookup(result, cb),
], (err, finalResult) {
if (err) {
console.error(err);
} else {
console.log(finalResult);
}
});
There are all sorts of helpful async primitives in there. I don't write Javascript without it!Here is a link to the documentation: https://github.com/caolan/async |
|