4 ms·
Would it? IIRC Promise.all will run the two responses in parallel, but will not send the first into the map before both are finished.
by coldtea 11y ago
Would it?
IIRC Promise.all will run the two responses in parallel, but will not send the first into the map before both are finished.
- awalGarg 11y agoPromise.all doesn't "run" anything. Promises "run" the very moment they come into existence. Promise.all simply tells you if and when all of them are settled. It depends on your Promises whether they are doing something outside the single threaded event loop or not for them to be parallel or not.
- girvo 11y ago> Promises "run" the very moment they come into existence Which is why I'm a massive fan of Futures from ramda-fantasy[0] instead of Promises for certain tasks! [0] https://github.com/ramda/ramda-fantasy/blob/master/docs/Future.md https://github.com/ramda/ramda-fantasy/blob/master/docs/Futu...
- coldtea 11y ago>Promise.all doesn't "run" anything. Promises "run" the very moment they come into existence. Yeah, I know that. I don't mean .all schedules them to run (e.g. like doing thread.start()), of course they auto start. By run I mean that inside the .all implementation syncs with you about their completion ("tells you when all of them are settled"). >It depends on your Promises whether they are doing something outside the single threaded event loop or not for them to be parallel or not. That's not the point though, which was the parent's assertion about whether the first to resolve will escape .all and go into the .map, which I don't think is the case.
- dvlsg 11y agoYes. They will be sent into map immediately, and Promise.all() will return a Promise which will settle when the mapped array is all settled (or one errors, but that's not really relevant to the question). We're really just awaiting the promise returned from Promise.all(), but mapping the original fetches into a "new" set of promises.
- jdgiese 11y agoI'm sorry, but I don't see why/how they would be sent to `map` immediately, given where the parenthesis are in the above code snippet. `Promise.prototype.map` isn't a builtin function is it? If the `map` call was inside the invocation of `Promise.all` then I could see it, but perhaps I am missing something.
- dvlsg 11y agoNo, you're right. That was a mistake on my part. The .map() should be called on the array, as calebegg pointed out.