My favorite JavaScript promise update in 8 years - withResolvers!

Sdílet
Vložit
  • čas přidán 9. 07. 2024
  • Promises. Awesome addition in ES6. But more was needed and more has come! withResolvers is a fantastic addition to ES14. It removes another "unnecessary" callback and give s more flexibility with our promises. This is exactly what ECMAScript updates should be doing! Get to using withResolvers (though not to fast, since support is still new), hit the subscribe button, and keep on top of JavaScript updates!
    0:00 - My favorite promise update in a long time
    1:29 - First look at docs
    2:10 - Promise example to work with
    3:18 - withResolvers()
    4:22 - Another callback? :(
    5:30 - My favorite thing... less tabs
    7:53 - Docs, second look
    9:25 - Another (advanced) use case
  • Věda a technologie

Komentáře • 3

  • @ahmad-murery
    @ahmad-murery Před 3 měsíci +2

    I like it, it looks more clear and easier to read.
    7:30 const {promise2, resolve2, reject2} = Promise.withResolvers()
    I think we'll get undefined for all of them.
    Maybe you meant
    const {promise: promise2, resolve: resolve2, reject: reject2} = Promise.withResolvers()
    Thanks Rob!

    • @robertbunch-dev
      @robertbunch-dev  Před 2 měsíci +1

      Yeah, an interesting addition. Obviously we can live without it, but as I said, forcing a callback to a thing that's supposed to eliminate callbacks seemed silly :) I could never bring myself to use "let" the way the docs show, so this is a nice option going forward. Thanks for posting!

    • @ahmad-murery
      @ahmad-murery Před 2 měsíci

      @@robertbunch-dev Yes we can live without it, but we always welcome a cleaner approach to do the thing.
      Thanks Rob!