2 ms·
This is an excellent comment. Thank you! I see what you mean – I am double-wrapping with Promises and could replace this with try{} catch{}. My error was that I
by nikodunk 7y ago
This is an excellent comment. Thank you! I see what you mean – I am double-wrapping with Promises and could replace this with try{} catch{}. My error was that I previously simply wrote
return course.email
or whatever, which as far as I could tell did not make the outer function wait.
I will correct this in the article once I've tested it.
- WorldMaker 7y agoYeah, the trick to remember is the await in the line before (and in general, anywhere you would .then() you can await, .catch() you can try/catch). You'll notice you can even `return await`, and that may have been the particular missing part you wanted. Where promises typically auto "flatten" their returns (return a Promise<T> in .then() and the return of .then() is a Promise<T> not a Promise<Promise<T>>), async/await does not flatten the promise automatically in case you meant to do that. If you are writing a lot of async/await code, you may want to take the time to configure your linter for promises/async/await or try Typescript, as either or both can be very useful tools at spotting cases where you missed an await before a Promise.