public < R > Promise < R > zipPromise ( final ListFunction < T , Promise < R > > fuc ) { return new Promise <> ( resolver -> { promises . then ( promises1 -> { final ArrayList < T > res = new ArrayList < T > ( ) ; for ( int i = 0 ; i < promises1 . length ; i ++ ) { res . add ( null ) ; } final Boolean [ ] ended = new Boolean [ promises1 . length ] ; for ( int i = 0 ; i < promises1 . length ; i ++ ) { final int finalI = i ; promises1 [ i ] . then ( t -> { res . set ( finalI , t ) ; ended [ finalI ] = true ; for ( int i1 = 0 ; i1 < promises1 . length ; i1 ++ ) { if ( ended [ i1 ] == null || ! ended [ i1 ] ) { return ; } } fuc . apply ( res ) . pipeTo ( resolver ) ; } ) ; promises1 [ i ] . failure ( e -> resolver . error ( e ) ) ; } if ( promises1 . length == 0 ) { fuc . apply ( res ) . pipeTo ( resolver ) ; } } ) ; promises . failure ( e -> resolver . error ( e ) ) ; } ) ; }
Zip array to single promise