Execute promises (async function) in parallel | JavaScript Interview Question - 67

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

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

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

    I think Promise.all executes concurrently not in parallel. A true parallel means like running task simultaneously on 2 threads. In JavaScript it can be done using web worker.
    Also can you explain in Promise.all where the settled promise are stored till other promise are still pending? It was asked in an interview. Your videos are wonderful keep making...

  • @amitavasengupta5580
    @amitavasengupta5580 6 месяцев назад +2

    Great content and such an elegant code but just one clarification, we can run promises parallely using promise.all() (fail fast) and promise.allSetteled() too right? And this example can be done using allSetted so if the interviewer asks to show parallel promises then which to show this code(which is simple and great explanation) or allSetted?

    • @Learnersbucket
      @Learnersbucket  6 месяцев назад

      Anythings works as long as it gives desired result

  • @skreddysasi3404
    @skreddysasi3404 Год назад +1

    Thanks for Sharing 🚀

  • @algobuddy
    @algobuddy Год назад +1

    Well explained 👍

  • @geekyasif
    @geekyasif Год назад +1

    very helpful

  • @sagarmusic0798
    @sagarmusic0798 11 месяцев назад +1

    Hi Prashant, I am not able to differentiate between this question and the prev one(async task in seq) could you please elaborate a bit

    • @Learnersbucket
      @Learnersbucket  11 месяцев назад

      In sequence second promise will start executing only after first is settled
      In parallel, All promises are executed parallelly

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

    Hi Prashant does promise.all and promise.settled execute async task parallely or concurrently. I have seen this question asked in many interviews . Want to know what should be we answer if this question is asked in interview

    • @Learnersbucket
      @Learnersbucket  Год назад +1

      If the response comes randomly this means they are run parallelly else if they return in input order then its concurrently. Now monitor the reponse of both yourself.

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

      Prashant, But in promise.all the result comes in the same sequence as provided in the input array but it calls all the async tasks parallelly.
      And that is because of
      Results[index] = value
      It uses index instead of push

    • @Learnersbucket
      @Learnersbucket  Год назад +1

      @@TechnoMob ohh, i see

  • @serveshchaturvedi2034
    @serveshchaturvedi2034 Год назад +1

    Great video Prashant! I wanted to know what is the difference between this approach and using promise.allsettled. thanks and keep them coming :)