public static CompletableFuture < Object > anyOf ( CompletableFuture < ? > ... cfs ) { int n ; Object r ; if ( ( n = cfs . length ) <= 1 ) return ( n == 0 ) ? new CompletableFuture < Object > ( ) : ( CompletableFuture < Object > ) uniCopyStage ( cfs [ 0 ] ) ; for ( CompletableFuture < ? > cf : cfs ) if ( ( r = cf . result ) != null ) return new CompletableFuture < Object > ( encodeRelay ( r ) ) ; cfs = cfs . clone ( ) ; CompletableFuture < Object > d = new CompletableFuture < Object > ( ) ; for ( CompletableFuture < ? > cf : cfs ) cf . unipush ( new AnyOf ( , , cfs ) ) ; // If d was completed while we were adding completions, we should // clean the stack of any sources that may have had completions // pushed on their stack after d was completed. if ( d . result != null ) for ( int i = 0 , len = cfs . length ; i < len ; i ++ ) if ( cfs [ i ] . result != null ) for ( i ++ ; i < len ; i ++ ) if ( cfs [ i ] . result == null ) cfs [ i ] . cleanStack ( ) ; return d ; }
Returns a new CompletableFuture that is completed when any of the given CompletableFutures complete with the same result . Otherwise if it completed exceptionally the returned CompletableFuture also does so with a CompletionException holding this exception as its cause . If no CompletableFutures are provided returns an incomplete CompletableFuture .