public static < T > CompletableFuture < T > delayedTask ( final Supplier < T > task , final Duration delay , final ScheduledExecutorService executorService ) { CompletableFuture < T > result = new CompletableFuture <> ( ) ; executorService . schedule ( ( ) -> result . complete ( runOrFail ( ( ) -> task . get ( ) , result ) ) , delay . toMillis ( ) , TimeUnit . MILLISECONDS ) ; return result ; }
Executes the given task after the specified delay .