export interface SettledPromises < T , V > { errors : V [ ] ; results : T [ ] ; } param { Promise < T > [ ] } promises param { Function } errFn returns export async function settleAll < T , V > ( promises , errFn ? ) ; export async function settleAll < T , V > ( promises , errFn ? ) ; export async function settleAll < T , V > ( promises , errFn ? ) ; export async function settleAll < T , V > ( promises , errFn ? ) ; export async function settleAll < T , V > ( promises , errFn = err => err ) { const intermediateResults = await Promise . all ( ( promises || [ ] ) . map ( async ( p , i ) => { try { return { results : await p } ; } catch ( err ) { return { errors : await errFn ( err , i ) } ; } } ) ) ; const settledPromises = { results : [ ] , errors : [ ] } ; for ( const result of intermediateResults ) { for ( const key in result ) { settledPromises [ key ] . push ( result [ key ] ) ; } } return settledPromises ; }