public <R> Promise<R> then(Success<? super T, ? extends R> success) { return promise.then(success); }
public <R> Promise<R> then(Success<? super T, ? extends R> success, Failure failure) { return promise.then(success, failure); }
public <R> Promise<R> then(Success<? super T, ? extends R> success, Failure failure) { return deferred.getPromise().then(success, failure); }
public <R> Promise<R> then(Success<? super T, ? extends R> success) { return deferred.getPromise().then(success); }
public Promise<Void> resolveWith(final Promise<? extends T> with) { if (with == null) throw new NullPointerException(); final PromiseImpl<Void> result = new PromiseImpl<Void>(exec, ses); with.then(new Success<T, T>() { @Override public Promise<T> call(Promise<T> resolved) throws Exception { if (isDone()) { result.fail(new IllegalStateException("associated Promise already resolved")); } PromiseImpl.this.resolve(resolved.getValue()); result.resolve(null); return null; } }, new Failure() { @Override public void fail(Promise<?> resolved) throws Exception { if (isDone()) { result.fail(new IllegalStateException("associated Promise already resolved")); } PromiseImpl.this.fail(resolved.getFailure()); result.resolve(null); } }); return result; }
/** * Resolve this Promise with the specified Promise. * * <p> * If the specified Promise is successfully resolved, this Promise is * resolved with the value of the specified Promise. If the specified * Promise is resolved with a failure, this Promise is resolved with the * failure of the specified Promise. * * @param with A Promise whose value or failure must be used to resolve this * Promise. Must not be {@code null}. * @return A Promise that is resolved only when this Promise is resolved by * the specified Promise. The returned Promise must be successfully * resolved with the value {@code null}, if this Promise was * resolved by the specified Promise. The returned Promise must be * resolved with a failure of {@link IllegalStateException}, if this * Promise was already resolved when the specified Promise was * resolved. */ Promise<Void> resolveWith(Promise<? extends T> with) { PromiseImpl<Void> chained = new PromiseImpl<Void>(); ResolveWith resolveWith = new ResolveWith(chained); with.then(resolveWith, resolveWith); return chained; }
promise.then(new Success<S, T>() { @Override public Promise<T> call(Promise<S> resolved) throws Exception {
backPressure.then(p -> { handleReset(resetWait); long toWait = p.getValue() - System.nanoTime();
backPressure.then(p -> { handleReset(resetWait); long toWait = p.getValue() - System.nanoTime();
backPressure.then(p -> { handleReset(resetWait); long toWait = p.getValue() - System.nanoTime();
.asTag() .async(uri); promises.add(async.then(resolved -> { switch (resolved.getValue() .getState()) {
.asTag() .async(uri); promises.add(async.then(resolved -> { switch (resolved.getValue() .getState()) {
releaseService(); }).then(null, new Failure(){ public void fail(Promise<?> resolved) throws Exception { logError("The fire-and-forget invocation failed", resolved.getFailure());
/** * Return a new Promise that will fail after timeout ms with a * {@link TimeoutException} */ // @Override public <T> CancellablePromiseImpl<T> before(Promise<T> promise, long timeout) { Deferred<T> d = new Deferred<T>(); Unique only = new Unique(); after(timeout).then((p) -> { only.once(() -> d.fail(TimeoutException.SINGLETON)); return null; }); promise.then((p) -> { only.once(() -> d.resolve(p.getValue())); return null; }, (p) -> { only.once(() -> d.fail(p.getFailure())); }); return new CancellablePromiseImpl<T>(d.getPromise()) { public boolean cancel() { try { return only.once(() -> d.fail(CancelException.SINGLETON)); } catch (Exception e) { return false; } } }; }