if (result != null) { BulkheadTransformer transformer = BulkheadTransformer.of(bulkhead).recover(recoveryFunction); result = result.transform(transformer);
if (result != null) { CircuitBreakerTransformer transformer = CircuitBreakerTransformer.of(breaker).recover(recoveryFunction); result = result.transform(transformer);
if (result != null) { RateLimiterTransformer transformer = RateLimiterTransformer.of(rateLimiter).recover(recoveryFunction); result = result.transform(transformer);
if (result != null) { RetryTransformer transformer = RetryTransformer.of(retry).recover(recoveryFunction); result = result.transform(transformer); RetryTransformer transformer = RetryTransformer.of(retry).recover(recoveryFunction); final Flux<?> temp = result; Promise<?> promise = Promise.async(f -> temp.collectList().subscribe(f::success, f::error)).transform(transformer); Flux next = Flux.create(subscriber -> promise.onError(subscriber::error).then(value -> { RetryTransformer transformer = RetryTransformer.of(retry).recover(recoveryFunction); final Mono<?> temp = result; Promise<?> promise = Promise.async(f -> temp.subscribe(f::success, f::error)).transform(transformer); Mono next = Mono.create(subscriber -> promise.onError(subscriber::error).then(subscriber::success)
@Override public <T> Promise<T> read(Promise<T> promise) { return promise.transform(up -> down -> new Access<T>(true, up, defaultTimeout, down)); }
@Override public <T> Promise<T> write(Promise<T> promise) { return promise.transform(up -> down -> new Access<T>(false, up, defaultTimeout, down)); }
@Override public <T> Promise<T> read(Promise<T> promise, Duration timeout) { return promise.transform(up -> down -> new Access<T>(true, up, timeout, down)); }
@Override public <T> Promise<T> write(Promise<T> promise, Duration timeout) { return promise.transform(up -> down -> new Access<T>(false, up, timeout, down)); }
return transform(up -> down -> { try { onYield.run();
@Override public Operation onError(Action<? super Throwable> onError) { return new DefaultOperation( promise.transform(up -> down -> up.connect(new Downstream<Void>() { @Override
/** * Transforms a failure of the given type (potentially into a value) by applying the given function to it. * <p> * This method is similar to {@link #mapError(Class, Function)}, except that it allows async transformation. * * @param function the transformation to apply to the promise failure * @return a promise * @since 1.3 */ default <E extends Throwable> Promise<T> flatMapError(Class<E> type, Function<? super E, ? extends Promise<T>> function) { return transform(up -> down -> up.connect(down.onError(throwable -> { if (type.isInstance(throwable)) { Promise<T> transformed; try { transformed = function.apply(type.cast(throwable)); } catch (Throwable t) { down.error(t); return; } transformed.connect(down); } else { down.error(throwable); } })) ); }
/** * Transforms a failure of the given type (potentially into a value) by applying the given function to it. * <p> * This method is similar to {@link #mapError(Function)}, except that it will only apply if the error is of the given type. * If the error is not of the given type, it will not be transformed and will propagate as normal. * * @param function the transformation to apply to the promise failure * @return a promise * @since 1.3 */ default <E extends Throwable> Promise<T> mapError(Class<E> type, Function<? super E, ? extends T> function) { return transform(up -> down -> up.connect(down.onError(throwable -> { if (type.isInstance(throwable)) { T transformed; try { transformed = function.apply(type.cast(throwable)); } catch (Throwable t) { down.error(t); return; } down.success(transformed); } else { down.error(throwable); } })) ); }
/** * Defers the subscription of {@code this} promise until later. * <p> * When the returned promise is subscribed to, the given {@code releaser} action will be invoked. * The execution of {@code this} promise is deferred until the runnable given to the {@code releaser} is run. * <p> * It is important to note that this defers the <i>subscription</i> of the promise, not the delivery of the value. * <p> * It is generally more convenient to use {@link #throttled(Throttle)} or {@link #onYield(Runnable)} than this operation. * * @param releaser the action that will initiate the execution some time later * @return a deferred promise */ default Promise<T> defer(Action<? super Runnable> releaser) { return transform(up -> down -> Promise.async(innerDown -> releaser.execute((Runnable) () -> innerDown.success(true)) ).then(v -> up.connect(down) ) ); }
/** * Transforms a failure of the given type (potentially into a value) by applying the given function to it. * <p> * This method is similar to {@link #mapError(Function)}, except that it allows async transformation. * * @param function the transformation to apply to the promise failure * @return a promise * @since 1.3 */ default Promise<T> flatMapError(Function<? super Throwable, ? extends Promise<T>> function) { return transform(up -> down -> up.connect(down.onError(throwable -> { Promise<T> transformed; try { transformed = function.apply(throwable); } catch (Throwable t) { down.error(t); return; } transformed.connect(down); })) ); }
return transform(up -> down -> up.connect(down.onError(throwable -> { if (predicate.apply(throwable)) {
return transform(up -> down -> up.connect( down.<T>onSuccess(value -> { try {
/** * Transforms a failure of the given type (potentially into a value) by applying the given function to it. * <p> * This method is similar to {@link #mapError(Predicate, Function)}, except that it allows async transformation. * * @param predicate the predicate to test against the error * @param function the transformation to apply to the promise failure * @return a promise * @since 1.6.0 */ default Promise<T> flatMapError(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends Promise<T>> function) { return transform(up -> down -> up.connect(down.onError(throwable -> { if (predicate.apply(throwable)) { Promise<T> transformed; try { transformed = function.apply(throwable); } catch (Throwable t) { down.error(t); return; } transformed.connect(down); } else { down.error(throwable); } })) ); }
return transform(up -> down -> up.connect(down.<T>onSuccess(value -> { try {
/** * Transforms a failure of the given type (potentially into a value) by applying the given function to it. * <p> * This method is similar to {@link #mapError(Function)}, except that it will only apply depending if it satisfies the predicate. * If the error is not of the given type, it will not be transformed and will propagate as normal. * * @param predicate the predicate to test against the error * @param function the transformation to apply to the promise failure * @return a promise * @since 1.6.0 */ default Promise<T> mapError(Predicate<? super Throwable> predicate, Function<? super Throwable, ? extends T> function) { return transform(up -> down -> up.connect(down.onError(throwable -> { if (predicate.apply(throwable)) { T transformed; try { transformed = function.apply(throwable); } catch (Throwable t) { down.error(t); return; } down.success(transformed); } else { down.error(throwable); } })) ); }