private < T > DeferredAction < M > deferAction ( final M metadata , final Supplier < ? extends CompletionStage < T > > action , final CompletableFuture < T > future ) { return new DeferredAction <> ( metadata , ( ) -> { final CompletionStage < ? extends T > resultFuture ; try { resultFuture = action . get ( ) ; } catch ( final Exception e ) { future . completeExceptionally ( e ) ; markProcessed ( metadata ) ; return ; } resultFuture . handleAsync ( ( result , e ) -> { if ( e != null ) { future . completeExceptionally ( e ) ; } else { future . complete ( result ) ; } markProcessed ( metadata ) ; return null ; } , executor ) ; } ) ; }
Defer the given action .