Check out a free preview of the full The Hard Parts of Asynchronous JavaScript course:
The "Wrapping Up Promises" Lesson is part of the full, The Hard Parts of Asynchronous JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

Will reviews the benefits and problems of Promises.

Get Unlimited Access Now

Transcript from the "Wrapping Up Promises" Lesson

[00:00:00]
>> Will Sentance: Good. So we have this new model for thinking about how our JavaScript executes. We are not alone anymore a synchronous language. We're a language that actually has a synchronicity built into it through the microtask queue. And in terms of how it interfaces with things outside of it as well, it has a ton of asynchronous features available to it in the Web browser.

[00:00:25] Excellent, so what is our problems with our final, or our solution three here, the promise based model? 99% of developers have no idea how these promise objects are working under the hood. They see .then, and they go my thread will return back up to there when future days get filled back in and then call display.

[00:00:46] So far from the truth. Instead, the then's only job of interest is to grab our display function and put it in future data's hidden unfulfillment properties, an array. Debugging becomes super-hard if you do not understand how this is happening under the hood. And unlike traditional asynchronous work, at least there you knew it was weird.

[00:01:07] Here it looks a little bit more meaningful. It masks the complexity, but benefits you understand it. You get a cleaner readable style with pseudo-synchronous code. These then methods being called give you a pseudo-synchronous style and it has a really nice error handling process. It's a really nice error handling process.

[00:01:26] If you go to parse, the second function, there's your error handler function. To be able to call .catch to add more error handling functions or it's an alternative way about handling errors. That's a really, really nice benefit of this model. And we're gonna see how final version at the very end of today, a single weight, doesn't give you as pretty way of handling errors actually.

[00:01:47] It's in theory step back, I guess, maybe not. I would say a step back from this very clean error handling way. Not a step back, but there's a way of handling errors which is perfectly fine. But this kinda I have my air handling function and I have my regular success function.

[00:02:03] That's pretty nice, that's a pretty nice model. All right, good. So promises, Web APIs, the Callback, Microtask Queue, Event loop [LAUGH] allow us to defer our actions until the work, the background heavy lifting work, the long time work, the slow work is completed. And continue running our code line by line in the meantime.

[00:02:21] Asynchronous JavaScript is the backbone of the modern web, letting us build fast non-blocking. We flow on while we let our background Web browser features do the slow work non-blocking applications. All right, beautiful.