“I Lost a Job Opportunity Just Because of Promise.all”
This is an interview experience that happened to my friend not long ago. The interviewer wanted him to implement the
Promise.all function. Unfortunately, my friend didn't play well on the spot and couldn't answer the question.
I’m actually puzzled by this behaviour of the interviewer. Does the inability to implement
Promise.all mean that the basics have not been mastered? That's strange, don't you think?
In what follows, I try to demystify
Promise.all and other important Promise methods. So let’s get started.
“The Promise.all() method takes an iterable of promises as an input, and returns a single Promise that resolves to an array of the results of the input promises.
This returned promise will fulfill when all of the input’s promises have fulfilled, or if the input iterable contains no promises.
It rejects immediately upon any of the input promises rejecting or non-promises throwing an error, and will reject with this first rejection message/error.”
Let’s write a few examples to review how to use
At this point, I think you already know how to implement it, it is very easy, right?
Have a test