Skip to content

Promise.all function that waits for all promises to be settled

License

Notifications You must be signed in to change notification settings

johanblumenberg/promise-allsettled

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

promise-settle-all

Similar to Promise.all, but unlike Promise.all, will not reject as soon as any of the given promises is rejected, but will wait for all of the given promises to be settled.

This is useful when you want all operations to complete, even if some of them fail, before the next action can take place.

For example, when testing you might want to close all connections at the end. You don't want the next test to start until all connections are closed, even if closing one of them fails.

Usage

import allSettled from 'promise-settle-all';

Promise.all([ Promise.reject(), fetch('https://example.com/index.html') ]).catch(err => {
    // This will execute immediately, while the call to fetch() is still pending
});

allSettled([ Promise.reject(), fetch('https://example.com/index.html') ]).catch(err => {
    // This will execute only after the call to fetch() is complete
});

About

Promise.all function that waits for all promises to be settled

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published