Receiving Promise <Pending> instead of value

邮差的信 提交于 2021-02-17 02:02:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!