@Test public void toFuture() { Promise<String> promise = Promise.<String>make().succeeded("hola mundo!"); Try<String> result = promise.get(); assertEquals(Try.success("hola mundo!"), result); }
@Override public Try<T> get() { if (isEmpty()) { synchronized (state) { if (isEmpty()) { try { state.wait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return Try.failure(e); } } } } return TryOf.narrowK(checkNonNull(reference.get())); }
PromiseImpl implements SealedPromise<T> { @Override public Try<T> get() { if (isEmpty()) { synchronized (state) { if (isEmpty()) { try { state.wait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return Try.failure(e); } } } } return TryOf.narrowK(checkNonNull(reference.get())); } }
PromiseImpl implements SealedPromise<T> { @Override public Try<T> get() { if (isEmpty()) { synchronized (state) { if (isEmpty()) { try { state.wait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return Try.failure(e); } } } } return TryOf.narrowK(checkNonNull(reference.get())); } PromiseImpl(Executor executor); }
PromiseImpl implements SealedPromise<T> { @Override public Try<T> get() { if (isEmpty()) { synchronized (state) { if (isEmpty()) { try { state.wait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return Try.failure(e); } } } } return TryOf.narrowK(checkNonNull(reference.get())); } 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 Try<T> get() { if (isEmpty()) { synchronized (state) { if (isEmpty()) { try { state.wait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return Try.failure(e); } } } } return TryOf.narrowK(checkNonNull(reference.get())); } 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);  }