@@ -408,6 +408,28 @@ const parallel = async (limit, array, func) => {
408408 }
409409 return results . map ( ( r ) => r . result ) ;
410410} ;
411+ async function all ( promises ) {
412+ const entries = isArray ( promises ) ? promises . map ( ( p ) => [ null , p ] ) : Object . entries ( promises ) ;
413+ const results = await Promise . all (
414+ entries . map (
415+ ( [ key , value ] ) => value . then ( ( result ) => ( { result, exc : null , key } ) ) . catch ( ( exc ) => ( { result : null , exc, key } ) )
416+ )
417+ ) ;
418+ const exceptions = results . filter ( ( r ) => r . exc ) ;
419+ if ( exceptions . length > 0 ) {
420+ throw new AggregateError ( exceptions . map ( ( e ) => e . exc ) ) ;
421+ }
422+ if ( isArray ( promises ) ) {
423+ return results . map ( ( r ) => r . result ) ;
424+ }
425+ return results . reduce (
426+ ( acc , item ) => ( {
427+ ...acc ,
428+ [ item . key ] : item . result
429+ } ) ,
430+ { }
431+ ) ;
432+ }
411433const retry = async ( options , func ) => {
412434 const times = options ?. times ?? 3 ;
413435 const delay = options ?. delay ;
@@ -888,4 +910,4 @@ const trim = (str, charsToTrim = " ") => {
888910 return str . replace ( regex , "" ) ;
889911} ;
890912
891- export { alphabetical , assign , boil , callable , camel , capitalize , chain , clone , cluster , compose , construct , counting , crush , dash , debounce , defer , diff , draw , first , flat , fork , get , group , guard , intersects , invert , isArray , isDate , isEmpty , isEqual , isFloat , isFunction , isInt , isNumber , isObject , isPrimitive , isString , isSymbol , iterate , keys , last , list , listify , lowerize , map , mapEntries , mapKeys , mapValues , max , memo , merge , min , objectify , omit , parallel , partial , partob , pascal , pick , proxied , random , range , reduce , replace , replaceOrAppend , retry , select , series , set , shake , shift , shuffle , sift , sleep , snake , sort , sum , template , throttle , title , toFloat , toInt , toggle , trim , tryit as try , tryit , uid , unique , upperize , zip , zipToObject } ;
913+ export { all , alphabetical , assign , boil , callable , camel , capitalize , chain , clone , cluster , compose , construct , counting , crush , dash , debounce , defer , diff , draw , first , flat , fork , get , group , guard , intersects , invert , isArray , isDate , isEmpty , isEqual , isFloat , isFunction , isInt , isNumber , isObject , isPrimitive , isString , isSymbol , iterate , keys , last , list , listify , lowerize , map , mapEntries , mapKeys , mapValues , max , memo , merge , min , objectify , omit , parallel , partial , partob , pascal , pick , proxied , random , range , reduce , replace , replaceOrAppend , retry , select , series , set , shake , shift , shuffle , sift , sleep , snake , sort , sum , template , throttle , title , toFloat , toInt , toggle , trim , tryit as try , tryit , uid , unique , upperize , zip , zipToObject } ;
0 commit comments