I have a function chain in a node 4.3 script that looks something like, callback -> promise -> async/await -> async/await -> async/await
like so:
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
}
(The reason it isn't async/await all the way through is that the top level function is a task queue library, and ostensibly can't be run async/await style)
If etcFunction() throws, does the error bubble up all the way to the top-level Promise?
If not, how can I bubble-up errors? Do I need to wrap each await in a try/catch and throw from there, like so?
async function doAnotherThing(data) {
try {
await etcFunction(data)
} catch(err) {
throw err
}
}
makePromise?async functions as tasks. You really shouldn't have to deal with callbacks. If you need to use a particular queue library that employs callback style, use a wrapper function.makePromiseis actually anasyncfunction, but since it's called from a non-asyncenvironment, i'm handling it like a promise. re: i agree, I'm going to try and promise-ify it eventually, but can I have reliable error bubbling in the mean time?makePromisebit from the snippet to clarify--the first function called in the top-level is anasync functioni'm treating as a regularPromise