

This looks nice and clean, but if we run it in our console we’ll notice an issue: the code now takes twice as long to run! 😱 - // this function simulates a request that needs to run async // - function getFakeData () doThings () We can see this in action by writing a function that simulates a slow network connection: when the function is called, it will wait 1 second before resolving (that’s Promise-jargon for “the asynchronous work is complete”). When sending off requests to load third-party data or do other asynchronous work, using a Promise has become a common pattern for telling our code to wait until the async work is done before continuing. This article will walk through a few examples and how they can be refactored to avoid blocking execution when using await. Create an array of Promises and await Promise.all instead. If you’re calling async functions with await, don’t let unrelated async calls block each other.To make sure your async code isn’t slowing down your apps, check your code to ensure that: This was relatively complex and involved the XMLHttpRequest API, but it really became popular with jQuery’s $.ajax() function, which made it more approachable.


Async ops are commonly used for data fetching, which is also referred to as Asynchronous JavaScript and XML (AJAX), a technique for sending requests from a web page that didn’t require refreshing the browser.
