Promise Code Challenge: The Case For .race

Sdílet
Vložit
  • čas přidán 9. 07. 2024
  • Put your JavaScript Promise skills to the test with .race() (though not required) in this Algorithm Monday video. The challenge is focused on making a fetch request, but having a bail out if it takes too long. These are an awesome way to improve your JavaScript and development skill! Hit subscribe so you don't miss another Algorithm Monday!
    Fetch Url = service.goodmorningdevelopers...
    Code: github.com/robertbunch/algori...
    0:00 - Challenge explanation
    1:15 - Psuedocode
    2:53 - Fetch Request
    3:55 - setTimeout reject
    4:42 - Promises array and .race()
    5:37 - Handling catches
    6:09 - Solution in action
    6:47 - Review solution
  • Věda a technologie

Komentáře • 5

  • @coreC..
    @coreC.. Před 3 měsíci +2

    Good morning!
    I just found your channel. You are quite handy at JS, and you explain things well.
    I know Javascript for quite a while, but lately i'm less into web-scripting as i used to be. One of my books (from 1997, author Laura Lemay) is titled: "Javascript 1.1". Nostalgia..
    Javascript has evolved nicely. Those promises, and async/await rock. And i don't see you end statements with a ; (that's new for me). I'm still learning.
    *Server took too long

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

      Welcome, and I'm glad you found the channel! I agree ... I miss the 1997 days when the web was simple, but async and await would be really hard to give up :)

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

    Hey Rob, this is a nice video (again).
    I know this is not about fetch API but, in the case of Too long request, isn't it better to abort the fetch promise so that we free up both client and server resources?
    Thanks!

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

      Yes, it's an incomplete process for sure. You definitely wouldn't want to leave those strings hanging. For clarity, rather than a 408, we are cutting off early for our own reasons, but the fetch needs to be cleaned up either way.
      Honestly, I couldn't think of a generic, realistic use case for race, so I kind of "forced" it.
      Good reminder!

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

      @@robertbunch-dev No problem, your example was clear enough 👍