tc39/proposal-promise-allSettled

Document more use cases

Closed this issue · 6 comments

Good to have references to other implementations, but it would be nice to have a little more information inline, including some realistic use cases.

const requests = URLs.map(x => fetch(x)); // some of these will fail, some will succeed

Promise.all(requests).then(() => {
  console.log('all requests have completed, now i can remove the loading indicator');
).catch(() => {
  console.log('but oops! at least one request has failed - but some of the requests still might not be finished!');
});

Promise.allSettled(requests).finally(() => {
  console.log('all requests are completed: either failed or succeeded, i don‘t care');
  removeLoadingIndicator();
});

Thanks @ljharb I've added that to the ReadMe
https://github.com/jasonwilliams/proposal-promise-allSettled#real-world-scenarios

@littledan do you feel we need a few more?

It might be good to outline why in that example all is not appropriate. Although it is pretty clear if you know the methods yourself, spelling it out will help people who are less involved understand things at a glance.

@domenic good point; updated.

More examples eventually would be good. I haven't been perfect about this in my repositories' explainers, but at least in some committee presentations it should be explained a little more. Maybe others can fill in suggestions here, or you can find some in existing library documentation.

Closing as the README now contains several examples.