Welcome to TechnoFunnel...
This video is focussed on the concept of Promises in JavaScript. Async Await is the new addition to ES6. Follow the article for more details:
/ javascript-async-await
/ mayank.gupta.6.88
Follow us on:
www.learn-javascript.in
technofunnel.in
JavaScript Introduces keywords “async” and “await” as an addition to EcmaScript 2015. In this article, we are going to talk about the following concepts. We are going to talk about the impact of each keyword on the JavaScript Execution.
Working With Async Keyword
Impact of Await Keyword
Returning Promises with Async Keyword
When we append the keyword “async” to the function, this function returns the Promise by default on execution. Async keyword provides extra information to the user of the function:
The function contains some Asynchronous Execution
The returned value will be the Resolved Value for the Promise.
Understanding Asynchronous Execution
Working with realtime scenarios, we might have some functions which return a promise on its execution. The promise returned from the function might resolve after some time, meanwhile, the main executing thread does not wait for the promise to be resolved, it proceeds further execution of the synchronous part of the application. Once the promise is resolved, its callback function is executed.
Working with the “await” keyword
Adding “await” before a promise makes the execution thread to wait for asynchronous task/promise to resolve before proceeding further. When we are adding the “await” keyword, we are introducing synchronous behavior to the application. Even the promises will be executed synchronously. Lets’s update the code above to replicate synchronous behavior.
The real advantage of async functions becomes apparent when you combine it with the await keyword — in fact, await only works inside async functions. This can be put in front of any async promise-based function to pause your code on that line until the promise fulfills, then return the resulting value. In the meantime, other code that may be waiting for a chance to execute gets to do so.
async/await is built on top of promises, so it's compatible with all the features offered by promises. This includes Promise.all() — you can quite happily await a Promise.all() call to get all the results returned into a variable in a way that looks like a simple synchronous code.
#technofunnel #react #javascript #frontend #promises #es6 #angular #es7 #es8 #techno funnel #technology #development #async #await #asynchronous #aws #golang #Java