@Test public void map() { Promise<String> promise = Promise.make(); Promise<String> map = promise.map(String::toUpperCase); Try<String> value = Try.success("hello world!"); executor.schedule(() -> promise.tryComplete(value), 500, TimeUnit.MILLISECONDS); assertEquals(value.map(String::toUpperCase), map.get()); }
@Override public <R> Promise<R> map(Function1<? super T, ? extends R> mapper) { Promise<R> other = new PromiseImpl<>(executor); onComplete(value -> other.tryComplete(value.map(mapper))); return other; }
PromiseImpl implements SealedPromise<T> { @Override public <R> Promise<R> map(Function1<? super T, ? extends R> mapper) { Promise<R> other = new PromiseImpl<>(executor); onComplete(value -> other.tryComplete(value.map(mapper))); return other; } }
PromiseImpl implements SealedPromise<T> { @Override public <R> Promise<R> map(Function1<? super T, ? extends R> mapper) { Promise<R> other = new PromiseImpl<>(executor); onComplete(value -> other.tryComplete(value.map(mapper))); return other; } PromiseImpl(Executor executor); }
PromiseImpl implements SealedPromise<T> { @Override public <R> Promise<R> map(Function1<? super T, ? extends R> mapper) { Promise<R> other = new PromiseImpl<>(executor); onComplete(value -> other.tryComplete(value.map(mapper))); return other; } PromiseImpl(Executor executor); @Override boolean tryComplete(Try<? extends T> value); @Override Try<T> get(); @Override Try<T> get(Duration timeout); @Override boolean isCompleted(); @Override Promise<T> onComplete(Consumer1<? super Try<? extends T>> consumer); @Override Promise<R> map(Function1<? super T, ? extends R> mapper); }
PromiseImpl implements SealedPromise<T> { @Override public <R> Promise<R> map(Function1<? super T, ? extends R> mapper) { Promise<R> other = new PromiseImpl<>(executor); onComplete(value -> other.tryComplete(value.map(mapper))); return other; } PromiseImpl(Executor executor); @Override boolean tryComplete(Try<? extends T> value); @Override Try<T> get(); @Override Try<T> get(Duration timeout); @Override boolean isCompleted(); @Override Promise<T> onComplete(Consumer1<? super Try<? extends T>> consumer); @Override Promise<R> map(Function1<? super T, ? extends R> mapper);  }