template T param promises returns export async function allDone < T > ( promises ) { let results = new Array < T > ( ) ; let firstError = null ; for ( let p of promises ) { try { results . push ( await p ) ; } catch ( e ) { if ( ! firstError ) firstError = e ; } } if ( firstError ) { throw firstError ; } else { return results ; } }