0
I would like to save the return of an asynchronous function. The function is as follows:
cb.tabela(serie).then(function(tabela) {
console.log(tabela);
}, function(err){
console.log(err);
});
I wish I could do something like:
cb.tabela(serie).then(function(tabela) {
return tabela;
}, function(err){
console.log(err);
});
but when I do I get one Promise {<pending>}
. Is there any way to save that return value?
The idea of working with asynchronous methods is precisely that there are no "stopped" code snippets, waiting for the resolution of slower snippets as external calls (the Fetch API is a good example). In this case, instead of returning table, you should call the function that needs it to continue, such as "montaTable(table);"...
– nunks
You have to "save that return" where you have it
console.log(tabela);
. Is there a problem putting that code there? , or a function call that passestabela);
?. You could use async/await, but if it’s too little, it might be simpler.– Sergio
Nunk.lol I tried to do this, to call a function to manipulate the data but I can’t access it, when I try to do this I get Promise {<pending too>}
– roooooon