dotJS 2017 - Wes Bos - Async + Await

  Рет қаралды 63,183

dotconferences

dotconferences

Күн бұрын

Filmed at 2017.dotjs.io on December 1st in Paris. More talks on dotconferences.com/talks
Flow Control in JavaScript is hard! Native Promises in JavaScript have helped immensely, but the syntax is still a little callback-y. With Async + Await, we can write synchronous looking code without losing any of the benefits of JavaScript's asynchronous nature.
Wes explores how async + await works, best practices for flow control, and explores several solutions for handling errors.

Пікірлер: 46
@XIAOx
@XIAOx 2 жыл бұрын
that girl who's laying down there is a mood
@maskenv231
@maskenv231 3 ай бұрын
i think she is disabled?
@Fuckingcoward
@Fuckingcoward Жыл бұрын
If you are here from the Odin project, congrates on making it this far.
@deveren
@deveren 5 ай бұрын
yaa man!
@schizo5189
@schizo5189 5 ай бұрын
let's fucking gooooo, fellow odinists
@Cloudjiek
@Cloudjiek 4 ай бұрын
Yo man, it's already 8 months. Have you finished this course?
@LazyBearHQ
@LazyBearHQ 3 ай бұрын
such a long journey
@Fuckingcoward
@Fuckingcoward 3 ай бұрын
@@Cloudjiek Yes. I'm employed rn. Although I'm not making 6 figures, it's a great start to get my foot in the door and work my way up to a higher comp as I gain more experience.
@alexnezhynsky9707
@alexnezhynsky9707 6 жыл бұрын
Wes Bos delivering top notch quality content, as always 👏
@ajinkyax
@ajinkyax 6 жыл бұрын
Thanks for showing `await Promise.all(...)` :) @8:03
@SamuelCarreira
@SamuelCarreira 6 жыл бұрын
Great talk! All perfect: great comunication and support slides
@daniilpanov2194
@daniilpanov2194 Жыл бұрын
I didn't know that Ewan McGregor is an expert in JS. Good for him!
@YuriPolchenko
@YuriPolchenko 5 жыл бұрын
Thanks! Awesome explanation
@DoctorFeral
@DoctorFeral 6 жыл бұрын
I was having breakfast while watching this :)
@muriukialex
@muriukialex 2 жыл бұрын
Great talk!
@raphaelmarot8282
@raphaelmarot8282 6 жыл бұрын
Thanks!
@aaron8989
@aaron8989 2 жыл бұрын
The parameters within the catchErrors function (req, res, next) are specific parameters to the getOrders function. If I wanted to wrap another function inside catchErrors that took a different set of parameters, would I need to define a new catchErrors function with these parameters inside? Sorry if this is a stupid question but I'm fairly new to coding.
@baka_baca
@baka_baca 2 жыл бұрын
Awesome talk! Seeing async/await years on after this video was posted, I have a couple of thoughts. I still use the Promise.then quite frequently alongside async/await because it let's me use a point-free style which I find cleaner in many cases. Why bother with a bunch of intermediate variables for data processing when I can cleanly have something like this "fetchData().then(camelCase).then(sendJson(res)).catch(next)". Also async/await is awesome, but I've seen a lot of developers get confused with it and make mistakes they simply wouldn't when using Promise.then. From writing blocking code by using multiple awaits on data calls that don't depend on each other, writing things like this "return await fetchData();" which just isn't necessary, and skipping writing a catch altogether because they think they must use a try/catch block which can be clunky to read and write (i.e. now we have another layer of nesting, sometimes more) instead of using a Promise.catch. Basically, it seems like as soon as developers discover async/await they seem to think they MUST use it in all cases and must never touch a Promise.then or Promise.catch again. I use async/await all the time just like I use Promise.then/catch all the time, I just try to use async/await more sparingly. I use async/await when I'm synchronizing large amounts of custom logic and data calls that won't come out clean with Promise.then. And I use Promise.then when I can nicely write in a point-free style and when I want to make it more clear that I am in fact returning a Promise. I get how async functions automagically wrap the return statement in a Promise for me, but with that detail hidden away I've gotten tripped up, as well as many others, that a Promise is being returned and not what the code says is being returned (i.e. where's the Promise in this line "return { data: formattedData };").
@stolensentience
@stolensentience 2 жыл бұрын
Don’t you have to write .then as a callback i.e. .then(x => x.camelCase)
@Textras
@Textras 6 жыл бұрын
Syntax.fm
@stolensentience
@stolensentience 2 жыл бұрын
That .find() syntax at 10:59 where you feed it an object… is that a thing? I error out when I try it.
@re.liable
@re.liable Жыл бұрын
that HOF is like a decorator right?
@rumax3440
@rumax3440 6 жыл бұрын
How to cancel await? You do a network request on button click and then user click it again, which will trigger new event and new await. Would be nice do describe such examples too.
@bharat9835
@bharat9835 6 жыл бұрын
rumax you would probably use throttle/debounce. If you really need cancelling you need to look at rxjs.
@JeanPatrickSmith
@JeanPatrickSmith 6 жыл бұрын
You can do a faux cancel by having something like: let status = 'good'; and in the response: if something else has happened, if (status === 'bad') > trash/ignore response, cache it, etc... very few cases where you should allow for that to happen. Like bharat said though if you actually need to cancel an async function mid stream, like for big data files or somethinig, than rxjs is your best bet. async/await is good for code readability and what not. In jQuery you can cancel ajax requests mid stream, and same with axios: medium.com/@muehler.v/node-js-meets-opencvs-deep-neural-networks-fun-with-tensorflow-and-caffe-ff8d52a0f072 So, depending on your library you can cancel manually, but async/await doesn't offer that out of the box.
@WesBos
@WesBos 6 жыл бұрын
A new AbortController() API is here / coming soon to cancel promises
@tilakmadichettitheappdeveloper
@tilakmadichettitheappdeveloper 3 жыл бұрын
when the bus says something, she-up-n-listen
@pierread1011
@pierread1011 6 жыл бұрын
Still not sold on the async/await thing. It was an interesting talk though, thanks for this!
@aNotoriousPhD
@aNotoriousPhD 6 жыл бұрын
opposed to what, .then chaining? Async/await is 10x more readable than .then's and callbacks.
@lasredchris
@lasredchris 4 жыл бұрын
flow control in javascript is hard promise - something that will happen in the future promise.all - wait for all those things to be done come back to it when we have the data what's the deal with then? asyc/await. substute for .then. We don't want to lock up the browser
@Minotauro_di_Chieti
@Minotauro_di_Chieti 3 жыл бұрын
This is not about async/awais, but axios!!
@stolensentience
@stolensentience 2 жыл бұрын
What.
@wepranaga
@wepranaga 5 жыл бұрын
the joke is a sink a weight
@tadeuasarro
@tadeuasarro 3 жыл бұрын
It took me some time
@stolensentience
@stolensentience 2 жыл бұрын
@@tadeuasarro hadda wait for it to uh, sink in?
@lamme4049
@lamme4049 4 жыл бұрын
I'm actually shocked that people think that it's easier to use async/await than normal promises
@baka_baca
@baka_baca 2 жыл бұрын
Agreed, async/await seems like it should be easier glancing at the code, but there's a significant amount of stuff you just have to know and keep in your head while reading and writing it. I use it all the time, but more sparingly than the Promise.then pattern.
@stolensentience
@stolensentience 2 жыл бұрын
@@baka_baca learning curve is higher (arguably) but the readability is too
@schizo5189
@schizo5189 5 ай бұрын
It just means you don't really understand promise. If you understand promise well, async/await is just syntatic sugar over them. The semantic is not that different
dotSwift 2020 - Erica Sadun - Property Wrappers
17:57
dotconferences
Рет қаралды 4,6 М.
3M❤️ #thankyou #shorts
00:16
ウエスP -Mr Uekusa- Wes-P
Рет қаралды 15 МЛН
Survival skills: A great idea with duct tape #survival #lifehacks #camping
00:27
Async JavaScript & Callback Functions -- Tutorial for Beginners
24:21
Advanced Async and Concurrency Patterns in JavaScript
39:43
Hack Reactor
Рет қаралды 140 М.
"Stop Using Async Await in .NET to Save Threads" | Code Cop #018
14:05
Netflix JavaScript Talks - RxJS + Redux + React = Amazing!
37:14
Netflix Engineering
Рет қаралды 393 М.
Wes Bos - Get better at JavaScript with just JavaScript
42:15
Jamstack TV
Рет қаралды 51 М.
🚀  TDD, Where Did It All Go Wrong (Ian Cooper)
1:03:55
DevTernity Conference
Рет қаралды 553 М.
Async Await vs. Promises - JavaScript Tutorial for beginners
24:30
The Async Await Episode I Promised
12:04
Fireship
Рет қаралды 1,1 МЛН
Здесь упор в процессор
18:02
Рома, Просто Рома
Рет қаралды 339 М.
Отдых для геймера? 😮‍💨 Hiper Engine B50
1:00
iPhone 16 с инновационным аккумулятором
0:45
ÉЖИ АКСЁНОВ
Рет қаралды 8 МЛН
⚡️Супер БЫСТРАЯ Зарядка | Проверка
1:00