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

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 พ.ย. 2024

ความคิดเห็น • 17

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

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

  • @skreddysasi3404
    @skreddysasi3404 ปีที่แล้ว +1

    Thanks for Sharing 🚀

  • @algobuddy
    @algobuddy ปีที่แล้ว +1

    Well explained 👍

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

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

  • @geekyasif
    @geekyasif ปีที่แล้ว +1

    very helpful

  • @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 :)