问题
I have a a object that when I'm printing that it's returning Promise <Pending>
(I've checked the type of getRateable
and it is object)
getRateable = getRateableEntitiesTx(tx, hashtagList);
I can't have access to the value by this :
getRateableEntitiesTx(tx, hashtagList).then((res) => {return res})
If it's a Promise
why it's not returning the res
properly?
Thanks in advance for help
回答1:
You can't return the value from an async function because the function returns before the value has been received. That's why we have promises. You need to use the value from within the then()
callback:
getRateableEntitiesTx(tx, hashtagList)
.then((rateable) => {
// use rateable here
console.log(rateable)
})
来源:https://stackoverflow.com/questions/53697842/receiving-promise-pending-instead-of-value