One of the hardest things about writing good JavaScript is dealing with heavily nested asynchronous code. Promises were created to solve the problem with callback hell, but there are still plenty of nested problems related to promises. This is where async/await comes in. JavaScript added async/await to allows developers to write asynchronous code in a way that looks and feels synchronous. This helps to remove many of the problems with nesting that promises have, and as a bonus can make asynchronous code much easier to read and write. In this video I am going to explain what async/await is and how to use async/await to rewrite your existing promise based code.
Learn Promises First:
Twitter:
Tweets by DevSimplified
GitHub:
https://github.com/WebDevSimplified
CodePen:
https://codepen.io/WebDevSimplified
#JavaScript #AsyncAwait #Promises
Original source
32 responses to “JavaScript Async Await”
Hi Kyle, can you explain all are we going to use promises.all along with async await?
So if I get it right.. Anything after the line of "await" keyword will only run when the promise has been resolved?
Like
await fetchSomething()
// Will only run when the fetchSomething Promise has been resolved
Way too fast for me to follow. Thanks anyway,
Guys if anyone can help me. The location and the response are presented as ${location} and ${response} respectively on my results. Any idea why? Thank you very much.
Dude.. async/await and promises had scared me for years.. uve made me understand them in 17 mins.. much much appreciated…
Nice and simple explanation. Thanks for taking the time to produce this (and the other) videos. Congrats!
Hhhahahaha good vid but I'm literally in bed amd you managed to make me slepp, tanks
so instead of declaring doWork, you could just do (async () => { //the code })() and have a neat readable entry point for your app right? nice video
please i wanna know so bad from which resources have u learned web development(especially nodejs and express) please ???
tell ya what, you're a fucking legend mate
nice usage of async await is create a "wait/pause" function with setTimeout
function wait(time) {
return new Promise(res => setTimeout(res,time));
}
async myMainFunction() {
//do something
//wait 1 second
await wait(1000);
//do something else
}
Thx god for you to exist
this is absolutely amaze.
my friend actually works at google and he always watches your tutorials and he told me to do that too.
I have an interview with amazon very soon.
I will try to refactor some of my projects that I built using promises since async await is way more clean than promise.
thanks very much brother
Dude you have really helped me out on this one, I really appreciate that
Came here with a knot in my brain for an additional perspective after finishing Brad Traversy's JS course on Udemy.
All the gears have finally clicked into place.
Subbed!
Great video, but I am a bit confused because around 3:45 you say the await keyword makes the async function to wait for the makeRequest to finish, but then you say around 4:10 the async function won't wait for the await function and keep on going. If you could clarify it would be helpful. Thanks
32 people still loving PHP .. jaja
Thanks so much for your videos, I really love them, you are one of my best favorite channels on youtube. I usually never comment, but this time I had to do it. greetings from Costa Rica
my brain exploded now. I thought that async-await turns sync an async function. thank you.
I have watched few videos on async/await over YouTube, but couldn't able to understand this concept. Then I have realized that I should make my foundation strong first on promise. Now I can clearly see how it's working under the hood. Anyway, nice explanation Kyle
Thanks for that, it's so confusing coming from a synchronous coding history
Well explained. Thank you!
Sweet and Simple example !!!
awesomeeee! <3
Well paced and not convoluted. Thanks!
Best explanation! Thanks
I really loved it ..thanks very much
Talks a mile a minute but a good teacher no less
great video man, a huge thank you from Brazil, but I have a question, if I have an async function inside another async function, do i need to put a try catch for each one?
You made it easy
are there any cases where using the promises syntax would be ideal over using async/await?
wow this guy explains it "Barney Style" I love it!
The best async await tutorial!