Hello! I have a very big question regarding the use of sync / await and tbm of Promise.all.
I have the following code:
class Conexao {
constructor(loading) {
this.loading = loading;
}
acessar(rota) {
return this.requisicao(rota, 1);
}
async requisicao(rota, id) {
let rotas = ['https://willianjusten.com.br/search.json']
rotas.push(rota);
await Promise.all(rotas.map(function(url) {
fetch(url).then(function(resp) {
return resp.json();
}).then(function(r) {
return r;
})
}));
}
}
let conn = new Conexao(true);
let result_final =
conn.acessar('https://jsonplaceholder.typicode.com/posts/');
console.log(result_final);
As I would do when calling the access function, wait for the return of the request function and after the return is complete, the variable result_final show what returned? I'm trying this way as I showed above, however or returns me undefined or [object promise].
There is no way to 'tell' the function to access (route) "Hey, wait for the function request to solve everything that will give you an answer and then yes you will send to result_final kkkkkkk best way I found to explain kkkkkkkkkkkkkkkk >
Could someone help me and explain to me what I'm doing wrong?
The code is in jsbin: link