down.success(recoverer.apply(t)); } else { down.error(t);
@Override public void onFailure(Throwable t) { error(t); } }, Execution.current().getEventLoop());
@Override public void onError(Throwable t) { if (!cancelled) { downstream.error(t); } }
protected void error(Downstream<?> downstream, Throwable error) { if (!fired && !disposed) { fired = true; downstream.error(error); } }
@Override public void failed(Throwable exc, A attachment) { error(exc); } };
@Override public void error(Throwable throwable) { Downstream.this.error(throwable); }
@Override public void error(Throwable throwable) { Downstream.this.error(throwable); }
@Override public void error(Throwable throwable) { try { action.execute(throwable); } catch (Exception e) { e.addSuppressed(throwable); Downstream.this.error(e); } }
@Override public void complete() { try { block.execute(); } catch (Exception e) { Downstream.this.error(e); } } };
@Override public void success(O value) { try { action.execute(value); } catch (Throwable e) { Downstream.this.error(e); } }
private static <T extends UserProfile> void toProfile(Class<T> type, Downstream<? super Optional<T>> downstream, Optional<UserProfile> userProfileOptional, Block onEmpty) throws Exception { if (userProfileOptional.isPresent()) { final UserProfile userProfile = userProfileOptional.get(); if (type.isInstance(userProfile)) { downstream.success(Optional.of(type.cast(userProfile))); } else { downstream.error(new ClassCastException("UserProfile is of type " + userProfile.getClass() + ", and is not compatible with " + type)); } } else { onEmpty.execute(); } }
private void tooLarge(Block onTooLarge, long length, Downstream<? super ByteBuf> downstream) { discard(); if (onTooLarge == RequestBodyReader.DEFAULT_TOO_LARGE_SENTINEL) { downstream.error(tooLargeException(length)); } else { try { onTooLarge.execute(); } catch (Throwable t) { downstream.error(t); return; } downstream.complete(); } }
@Override public void error(Throwable throwable) { if (fire()) { continuation.resume(() -> downstream.error(throwable)); } else { DefaultExecution.LOGGER.error("", new OverlappingExecutionException("promise already fulfilled", throwable)); } }
private void timeout() { if (fire()) { continuation.resume(() -> { drain(); downstream.error(new TimeoutException("Could not acquire " + (read ? "read" : "write") + " access within " + timeout)); }); } }
/** * Signals this downstream, based on the given result. * * @param result the result to signal */ default void accept(Result<? extends T> result) { if (result.isError()) { error(result.getThrowable()); } else { success(result.getValue()); } }
private Promise<ByteBuf> invoke() { return Promise.async(f -> { ByteBuf byteBuf = bufferAllocator.ioBuffer(); try { CompiledTextTemplate fromCache = getFromCache(compiledTemplateCache, templateSource); Render.this.execute(fromCache, model, byteBuf); f.success(byteBuf); } catch (Throwable e) { byteBuf.release(); f.error(e); } } ); }
@Override public Operation forEach(BiAction<? super Integer, ? super T> consumer) { return Promise.<Void>async(d -> yieldPromise(promises.iterator(), 0, (i, r) -> consumer.execute(i, r.getValue()), (i, r) -> { d.error(r.getThrowable()); return false; }, () -> d.success(null)) ).operation(); }
/** * Signals this downstream, based on the given result. * * @param result the result to signal */ default void accept(ExecResult<? extends T> result) { if (result.isComplete()) { complete(); } else if (result.isError()) { error(result.getThrowable()); } else { success(result.getValue()); } }