When we have an async function that returns a variable, and then .then() is run...
What does .then() accept as parameters?
Is it the variable that async returns?
For example, consider this node.js example:
const js_package = require('random_js_package');
var random_variable;
let js_function = async () => {
random_variable = js_package();
return random_variable;
}
js_function().then((value) => {
for (var i=0; i<value.length; i++){
console.log(value[i]);
}
});
In this case, is the variable called value inside .then() what the async function returns?
In other words, is value the same as random_variable?
random_variableis a value, thenvaluewill indeed be the same asrandom_variable. Ifjs_package()returns Promise, thenvaluewill be whatever that Promise eventually delivers ... unless the Promises error path is taken, in which case the.then()callback won't be called at all; you need to chain.catch(errorHandler)in case that happens.