Can I iterate over/get an iterable over multiple promises by order of their settlement?

1 day ago 1
ARTICLE AD BOX

In my code, I have a bunch of asynchronous tasks, which will be represented as Promises. Say, let those be:

let promises = myarr.map( (x) => myAsyncFn(x) );

I want to trigger some action after each settlement of one of these promises; but I don't want to wait until they're all settled.

Now, I know I can get the first Promise out of all of those which is settled, with Promise.race(promises). But that will get me just one promise, and no object with the rest of the promises. What I would like to have is an iterator, or perhaps a transformation of promises into an iterable of Promises, in the order of settlement, such that looping on it means waiting for the next one to settle, and the next one and so on.

Read Entire Article