require ( 'promise.allsettled/auto' ) ; param promises param errorMessage export async function finishAll ( promises , errorMessage ? ) { const settledPromises = await Promise . allSettled ( promises ) ; const rejectedPromises = settledPromises . filter ( promise => promise . status === 'rejected' ) as PromiseRejectedResult [ ] ; if ( rejectedPromises . length ) { const reasons = rejectedPromises . map ( promise => `\t${ promise . reason }` ) . join ( '\n' ) ; const message = errorMessage ? `${ errorMessage } ` : '' ; throw new Error ( `${ message }Errors: [\n${ reasons }\n]` ) ; } }