node 4.3スクリプトに、コールバック -> promise -> async/await -> async/await -> async/await のような関数チェーンがあります。
そのようです:
const topLevel = (resolve, reject) => {
const foo = doThing(data)
.then(results => {
resolve(results)
})
.catch(err => {
reject(err)
})
}
async function doThing(data) {
const thing = await doAnotherThing(data)
return thing
}
async function doAnotherThing(data) {
const thingDone = await etcFunction(data)
return thingDone
}
(完全ではない理由はasync/await、最上位の関数がタスク キュー ライブラリであり、表向きは実行async/awaitスタイルにできないためです)
etcFunction()がスローされた場合、errorバブルはトップレベルまで上がりますPromiseか?
そうでない場合、どうすればバブルアップできerrorsますか? そのように、そこからandでそれぞれawaitをラップする必要がありますか?try/catchthrow
async function doAnotherThing(data) {
try {
await etcFunction(data)
} catch(err) {
throw err
}
}