Working with Async/Await

If we want to fetch data out of the server, the best tool for us to do that is by using some new Javascript syntax around asynchronous actions and calls!

This is called Async/Await, and is a method of performing operations that don't require our application to completely hang, but will wait for results while processing other data. If you're familiar with promises, you might be familiar with code that looks something like this:

doSomethingAsync().then(doSomething()).then(doSomethingElse())

This is fine, but there is a better way to do this. This code can get particularly messy the larger it grows, and even more so if we introduce different branches or failure criteria and conditions we need to account for. Eventually, a mess of promises can turn into code that is just impossible to trace through when things go wrong, and we want to avoid that if we can.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.42.196