|
|
|
|
|
by account_taken
4833 days ago
|
|
These kinds problems can easily be solved with promises too. It would be even simpler if `fs.stat` returned a promise and there are promise libraries that do that. Promises is a small library I use, probably about the same number of bytes as your library, as I transition my code from callbacks to promises. var queue = new Promises;
fs.stat("file1.txt", queue.cb());
fs.stat("file2.txt", queue.cb());
fs.stat("file2.txt", queue.cb());
queue.all()
.then()
.fail();
But, comparing how promises solves the same flow as callbacks misses the point. Here's an example where an action is taken when two events fire (promises shine here): pub.on('foo', function() {
promise1.fulfill();
});
pub.on('bar', function() {
promise2.fullfill();
});
Vow.all([promise1, promise2]).then(...).fail(...);
|
|