@Test public void sleep() { long start = System.currentTimeMillis(); Future.sleep(Duration.ofSeconds(1)).andThen(Future.success("ok")).await(); long elapsedTime = System.currentTimeMillis() - start; assertTrue(1000 - elapsedTime < 100, () -> "it should wait for almost 1 sec, but it was " + elapsedTime); }
protected static Future<Unit> sleep(Executor executor, Duration delay) { checkNonNull(executor); checkNonNull(delay); return from(executor, FutureModule.sleep(executor, delay)); }
FutureImpl implements SealedFuture<T> { protected static Future<Unit> sleep(Executor executor, Duration delay) { checkNonNull(executor); checkNonNull(delay); return from(executor, FutureModule.sleep(executor, delay)); } }
FutureImpl implements SealedFuture<T> { protected static Future<Unit> sleep(Executor executor, Duration delay) { checkNonNull(executor); checkNonNull(delay); return from(executor, FutureModule.sleep(executor, delay)); } private  FutureImpl(Executor executor, Callback<T> callback); private  FutureImpl(Executor executor, Callback<T> callback, Propagate propagate); }
FutureImpl implements SealedFuture<T> { protected static Future<Unit> sleep(Executor executor, Duration delay) { checkNonNull(executor); checkNonNull(delay); return from(executor, FutureModule.sleep(executor, delay)); } private  FutureImpl(Executor executor, Callback<T> callback); private  FutureImpl(Executor executor, Callback<T> callback, Propagate propagate); @Override Future<T> onComplete(Consumer1<? super Try<? extends T>> consumer); @Override Future<T> onSuccess(Consumer1<? super T> consumer); @Override Future<T> onFailure(Consumer1<? super Throwable> consumer); @Override boolean isCompleted(); @Override boolean isCancelled(); @Override Try<T> await(); @Override Try<T> await(Duration timeout); @Override Future<R> map(Function1<? super T, ? extends R> mapper); @Override Future<R> flatMap(Function1<? super T, ? extends Future<? extends R>> mapper); @Override Future<R> andThen(Future<? extends R> next); @Override Future<R> ap(Future<Function1<? super T, ? extends R>> apply); @Override Future<T> filter(Matcher1<? super T> matcher); @Override Future<T> orElse(Future<? extends T> other); @Override Future<T> recoverWith(Class<X> type, Function1<? super X, ? extends T> mapper); @Override Future<U> fold(Function1<? super Throwable, ? extends U> failureMapper, Function1<? super T, ? extends U> successMapper); @Override void cancel(boolean mayInterruptThread); @Override Promise<T> toPromise(); }
FutureImpl implements SealedFuture<T> { protected static Future<Unit> sleep(Executor executor, Duration delay) { checkNonNull(executor); checkNonNull(delay); return from(executor, FutureModule.sleep(executor, delay)); } private  FutureImpl(Executor executor, Callback<T> callback); private  FutureImpl(Executor executor, Callback<T> callback, Propagate propagate); @Override Future<T> onComplete(Consumer1<? super Try<? extends T>> consumer); @Override Future<T> onSuccess(Consumer1<? super T> consumer); @Override Future<T> onFailure(Consumer1<? super Throwable> consumer); @Override boolean isCompleted(); @Override boolean isCancelled(); @Override Try<T> await(); @Override Try<T> await(Duration timeout); @Override Future<R> map(Function1<? super T, ? extends R> mapper); @Override Future<R> flatMap(Function1<? super T, ? extends Future<? extends R>> mapper); @Override Future<R> andThen(Future<? extends R> next); @Override Future<R> ap(Future<Function1<? super T, ? extends R>> apply); @Override Future<T> filter(Matcher1<? super T> matcher); @Override Future<T> orElse(Future<? extends T> other); @Override Future<T> recoverWith(Class<X> type, Function1<? super X, ? extends T> mapper); @Override Future<U> fold(Function1<? super Throwable, ? extends U> failureMapper, Function1<? super T, ? extends U> successMapper); @Override void cancel(boolean mayInterruptThread); @Override Promise<T> toPromise();  }