public static < T , R > Function < T , ListenableFuture < R > > futureWith ( final ListeningExecutorService executor , final Function < T , R > task , final FutureCallback < R > callback ) { checkArgument ( executor != null , "Expected non-null executor" ) ; checkArgument ( task != null , "Expected non-null task" ) ; checkArgument ( callback != null , "Expected non-null callback" ) ; return input -> { ListenableFuture < R > future = executor . submit ( ( ) -> task . apply ( input ) ) ; addCallback ( future , callback , executor ) ; return future ; } ; }
Function submits the task with given executor and callback