If you have faced a code like below, then this article will help you in multiple ways 😁.
fetchPizzas()
.then((pizzas) => {
return sortByTo...
For further actions, you may consider blocking this person and/or reporting abuse
I’m not sure why the first block of code in the article uses promises like the old callback hell, but here it is the proper way to write that first block of code:
And, in my opinion, it looks better then the alternatives offered by the article, not mentioning the testability of it.
Agree, I think promises are better that
async/await
when it comes to function composition.That was a bad example, not to be used
Thanks for the post Yaser!
One thing I'd add is that although we don't have top-level await, it's most likely going to happen as it's at Stage 3.
tc39 / proposal-top-level-await
top-level `await` proposal for ECMAScript (stage 3)
ECMAScript proposal: Top-level
await
Champion: Myles Borins
Status: Stage 3
Synopsis
Top-level
await
enables modules to act as big async functions: With top-levelawait
, ECMAScript Modules (ESM) canawait
resources, causing other modules whoimport
them to wait before they start evaluating their body.Motivation
Limitations on IIAFEs
With
await
only available withinasync
functions, a module can include anawait
in the code that executes at startup by factoring that code into anasync
function:This pattern can also be immediately invoked. You could call this an Immediately Invoked Async Function Expression (IIAFE), as a play on IIFE idiom.
Thanks for sharing, didn't know about this 👌🏽
Updated the post to reflect this, thanks again Nick
Great article Yaser! btw:
AsyncFuncton
->AsyncFunction
Nice catch, I should double check my spell checker in VS Code
Good read, but I believe next to last code line should be ‘deliver()’. Also, looking for more on thenable, any good coverage somewhere? Thanks!!
Fixed, thanks, check this out promisesaplus.com/
Just what I needed when I needed. Thank you!!
You're welcome, glad it helped