- Recommended that you stick with aynchronous code whenever possible
- Synchronous code is blocking for all users since it's single threaded process
- Blocking code isn't that big of a deal with one user, but with additional users it becomes a huge problem
- Requires a different way of thinking when it comes to your code
Synchronous
var data = fs.readFileSync('/etc/passwd');Asynchronous
fs.readFile('/etc/passwd', function(err, data) {
// ...
} );function(err, data) {
// ...
}async.waterfall([
function(callback) {
callback(null, 'one', 'two');
},
function(arg1, arg2, callback) {
// arg1 now equals 'one' and arg2 now equals 'two'
callback(null, 'three');
},
function(arg1, callback) {
// arg1 now equals 'three'
callback(null, 'done');
}
], function (err, result) {
// result now equals 'done'
});