首页 文章

接收承诺<待定>而不是 Value

提问于
浏览
1

我有一个对象,当我'm printing that it'返回 Promise <Pending> (我已经检查了 getRateable 的类型,它是对象)

getRateable = getRateableEntitiesTx(tx, hashtagList);

我无法通过此访问该值:

getRateableEntitiesTx(tx, hashtagList).then((res) => {return res})

如果它是 Promise 为什么它没有正确返回 res

在此先感谢您的帮助

1 回答

  • 0

    你可以't return the value from an async function because the function returns before the value has been received. That'为什么我们有承诺 . 您需要使用 then() 回调中的值:

    getRateableEntitiesTx(tx, hashtagList)
    .then((rateable) => {
      // use rateable here
      console.log(rateable)
     })
    

相关问题