Async function returns [object Promise]

后端 未结 2 676
伪装坚强ぢ
伪装坚强ぢ 2021-01-28 16:14

I\'m trying to return an async function but I either get promise: < { PENDING } > or [object Promise] instead of [object Object]

2条回答
  •  庸人自扰
    2021-01-28 16:36

    You cannot make asynchronous code synchronous.

    The await keyword lets you write code that looks synchronous, but is really asynchronous.

    You can only use await inside a function which is async.

    To make await work, all async functions return promises. Those promises resolve to be the return value of the function.

    In short: You have the normal and expected behaviour, and you can't prevent an async function from returning a promise.

提交回复
热议问题