Less indentation
suggest changeWith promises:
function doTheThing() {
return doOneThing()
.then(doAnother)
.then(doSomeMore)
.catch(handleErrors)
}
With async functions:
async function doTheThing() {
try {
const one = await doOneThing();
const another = await doAnother(one);
return await doSomeMore(another);
} catch (err) {
handleErrors(err);
}
}
Note how the return is at the bottom, and not at the top, and you use the languageās native error-handling mechanics (try/catch
).
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents