0
const url = 'http://files.cod3r.com.br/curso-js/funcionarios.json'
const axios = require('axios')
const busca = () =>{
return new Promise((resolve, reject) =>{
try{
const funcionarios = axios.get(url).then(resp => resp.data)
resolve(funcionarios)
}
catch(e){
reject(e)
}
})
}
async function getFuncionarios(){
const funcionarios = await busca().then(resp => resp)
return funcionarios
}
const fcs = getFuncionarios()
fcs
should be loaded with all the functionalities of the url, but only Promise{}. Where is the error ?
axios.get()
returns a file, I solve it with the then() and play the result (Resp.data) in the const files
and I pass it in the resolve() of my own Promise. In the other function I leave it as async and place await in the busca().then(resp => resp)
solving my own promise and talking to wait and then return the result
Sorack, the return value of a
async
is aPromise
. In your examplefcs
is aPromise
– Sergio
Friend, you forgot the search() Return, but even with it does not produce the expected result, continue with Promise{<pending>}.
– Kevin Ricci
@Sergio truth
– Sorack
I understood, however, it will always stay in this cycle ? I will never be able to take the value and store it in a variable that does not become a Promise ?
– Kevin Ricci
@Kevinricci no, always like this.
– Sorack