I am 100% sure there must be some simple answer but today I suck at googling. Question within the code.
async.waterfall([
function(callback){
callback(null, 'some value..');
}
],
function (err, result) {
// how do I get result outside of this block?
}
);
If I set a variable outside this block and try to assign "result" to it, it does not make out of the block because of the nature of JavaScript scopes..
Thanks!
Thanks everyone for your answers. What I've done - I've switched to a module called "step" instead. It lets me do the following:
step = require('step');
var responseData = '{"a":1, "b":2}';
step(
function someFunction1 () {
// We do something here and return the result
return '3';
},
function someFunction2 (err, result) {
// We try to modify the variable that has been defined outside this block
responseData.c = result;
}
);
// responseData now returns {"a":1, "b":2, "c":3}
Maybe I could have done something like this with async as well - I don't know. But the above works just the way I wanted.