dotJS 2017 - Wes Bos - Async + Await

Поделиться
HTML-код
  • Опубликовано: 12 дек 2024

Комментарии • 56

  • @owaissonija7339
    @owaissonija7339 3 месяца назад +37

    If you are here from the Odin project, you did great job so far by being persistent. Best of luck ahead!

    • @thatmehdude
      @thatmehdude Месяц назад

      feels like the end is still too far man.

    • @mridhulml3269
      @mridhulml3269 Месяц назад

      yoo thank you! really needed that rn.

    • @mridhulml3269
      @mridhulml3269 Месяц назад

      @@thatmehdude yea same...I'm considering jumping to full stack open after skimming through js section

    • @AmanSingh-vy5tk
      @AmanSingh-vy5tk 17 дней назад

      man lets connect we are not far from each-other in course road, hoping the learning is going good and job is not too far

    • @owaissonija7339
      @owaissonija7339 17 дней назад

      @@AmanSingh-vy5tk send your number/contact

  • @alexnezhynsky9707
    @alexnezhynsky9707 6 лет назад +25

    Wes Bos delivering top notch quality content, as always 👏

  • @XIAOx
    @XIAOx 2 года назад +24

    that girl who's laying down there is a mood

    • @eiririiii
      @eiririiii 8 месяцев назад +1

      i think she is disabled?

  • @ajinkyax
    @ajinkyax 7 лет назад +26

    Thanks for showing `await Promise.all(...)` :) @8:03

  • @SamuelCarreira
    @SamuelCarreira 6 лет назад +7

    Great talk! All perfect: great comunication and support slides

  • @daniilpanov2194
    @daniilpanov2194 Год назад +2

    I didn't know that Ewan McGregor is an expert in JS. Good for him!

  • @jntlmb
    @jntlmb Месяц назад +1

    is this a talk tuah reference?

  • @DoctorFeral
    @DoctorFeral 6 лет назад +4

    I was having breakfast while watching this :)

  • @YuriPolchenko
    @YuriPolchenko 6 лет назад +1

    Thanks! Awesome explanation

  • @baka_baca
    @baka_baca 2 года назад +4

    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)

  • @aaron8989
    @aaron8989 2 года назад +1

    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.

  • @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.

  • @muriukialex
    @muriukialex 2 года назад

    Great talk!

  • @re.liable
    @re.liable Год назад

    that HOF is like a decorator right?

  • @rumax3440
    @rumax3440 7 лет назад +1

    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 7 лет назад +1

      rumax you would probably use throttle/debounce. If you really need cancelling you need to look at rxjs.

    • @JeanPatrickSmith
      @JeanPatrickSmith 7 лет назад +1

      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 7 лет назад +9

      A new AbortController() API is here / coming soon to cancel promises

  • @raphaelmarot8282
    @raphaelmarot8282 6 лет назад +1

    Thanks!

  • @Textras
    @Textras 6 лет назад +13

    Syntax.fm

  • @pierread1011
    @pierread1011 6 лет назад +2

    Still not sold on the async/await thing. It was an interesting talk though, thanks for this!

    • @aNotoriousPhD
      @aNotoriousPhD 6 лет назад +10

      opposed to what, .then chaining? Async/await is 10x more readable than .then's and callbacks.

  • @lasredchris
    @lasredchris 5 лет назад

    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

  • @tilakmadichettitheappdeveloper
    @tilakmadichettitheappdeveloper 3 года назад

    when the bus says something, she-up-n-listen

  • @Minotauro_di_Chieti
    @Minotauro_di_Chieti 4 года назад

    This is not about async/awais, but axios!!

  • @wepranaga
    @wepranaga 5 лет назад +8

    the joke is
    a sink a weight

    • @tadeuasarro
      @tadeuasarro 4 года назад

      It took me some time

    • @stolensentience
      @stolensentience 2 года назад +3

      @@tadeuasarro hadda wait for it to uh, sink in?

    • @salwacoding5661
      @salwacoding5661 3 месяца назад +1

      @@stolensentience Loool That got me laugh more than the original joke.

  • @lamme4049
    @lamme4049 4 года назад +1

    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 10 месяцев назад

      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