Sorry for the incorrect name of the question, as I do not know how to clearly describe it.
I just met a problem when I use async.waterfall and fix it finally. But I still do not know what is going on behind this.
What I found:
When we use async.waterfall, the parameterThe last task should be the same as the next task. Otherwise, he will say "undefined is not a function".
I tried some tests and I am also trying to figure out its source code . Sorry, I'm new to JavaScript. I could not understand a lot of javascript template. This is too hard for me.
After fighting with the source code for more than two hours, I need help. Could you give me some advice on these two issues:
- how does it handle the error , in what situation will it go to the last callback?
According to my test result, '', null,undefinedit will not lead to a jump. This behavior makes sense to me.
- Why should the number of parameters be the same?
If you pass only one argument in the last task, of course, the callback will be undefined. But I would like to know a lot about this.
I can know these words: apply, close, etc., when they are separated in simple demos. But when they come together, I become blind.
Both the short answer and the long answer are much appreciated. If possible, perhaps you can provide some links and I can study it myself.
.
:
var async = require('async');
function test_waterfall() {
async.waterfall([
function(callback) {
callback()
},
function(arg, callback) {
callback(null, arg+'2');
}
], function(err, result) {
console.info(err)
console.info(result)
});
}
test_waterfall()