假设我有这个代码:
const myFunction = async => {
const result = await foobar()
}
const foobar = async () => {
const result = {}
result.foo = await foo()
result.bar = await bar()
return result
}
Run Code Online (Sandbox Code Playgroud)
我想要这个:
const myFunction = () => {
const result = foobar()
}
Run Code Online (Sandbox Code Playgroud)
我尝试像这样包装foobar :
const foobar = async () => {
return (async () => {
const result = {}
result.foo = await foo()
result.bar = await bar()
return result
})()
}
Run Code Online (Sandbox Code Playgroud)
但这仍然返回一个承诺
我不能在 …