JavaScript has always had an asynchronous nature. Most of the web's APIs were synchronous though, but things eventually changed also thanks to func...
For further actions, you may consider blocking this person and/or reporting abuse
I switch between async/await and plain promises often. I also mix await with .catch()
Some code gets simpler with await, especially when I need to mix results of multiple promises and following requests are based on the results of the last ones.
Some code gets simpler with plain promises, like parallelisation. When I need to retrieve the data of multiple views in one screen I often drop them off as promise and then the result into the views when they arrive.
Instead of this you can do something like the following:
Or like this:
Clean and simple approach, but passing around of all the values is quite cumbersome.
My main point was that you can still get a "flat" result when you have interdependent calls.
You can also pull this off with callbacks.
The 'tip' from Cory House that you shared in this article is an anti pattern that should be avoided.
If the
doSomething()anddoSomethingElse()from your example both throw, you will get an unhandled exception warning - only the first exception will be caught. This can lead to hard-to-debug warnings.Promise.allis the safe way to execute multiple async processes in parallel.Very interesting! I'm not an expert in javascript and I have faced this callback hell sometimes.
I use the caolan/async module to solve this in nodejs and also for web pages, is there any problem I'm missing? Like loosing too much performance or other things?
Nice post. I've had a bit of a modern JS phobia I'm just starting to shake and this helps.
This is an eye-opener. Also, my kittens like this post. ;) :)