/** * Creates a new {@link Eventual} object from given value. * * @param value the emitted value * @param <T> an element type * @return an {@link Eventual} object */ public static <T> Eventual<T> of(T value) { return fromMono(Mono.just(value)); }
/** * Creates a new (@link Eventual} that emits an error. * * @param error a {@link Throwable} object * @param <T> an element type * @return an {@link Eventual} object */ public static <T> Eventual<T> error(Throwable error) { return fromMono(Mono.error(error)); }
/** * Transforms an element synchronously by applying a mapping function. * * @param transformation a mapping function * @param <R> new event type * @return a new {@link Eventual} with mapping applied */ public <R> Eventual<R> map(Function<? super T, ? extends R> transformation) { return fromMono(Mono.from(publisher).map(transformation)); }
/** * Creates a new {@link Eventual} from a {@link CompletionStage}. * * @param completionStage a {@link CompletionStage} instance * @param <T> an event type * @return an {@link Eventual} object */ public static <T> Eventual<T> from(CompletionStage<T> completionStage) { return fromMono(Mono.fromCompletionStage(completionStage)); }
/** * Transform an element asynchronously by applying a mapping function. * * @param transformation a mapping function * @param <R> new event type * @return a new {@link Eventual} with mapping applied */ public <R> Eventual<R> flatMap(Function<? super T, ? extends Eventual<? extends R>> transformation) { return fromMono(Mono.from(publisher).flatMap(value -> Mono.from(transformation.apply(value)))); }
/** * Transforms an error by applying an error handler function. * * @param errorHandler an error handler function * @return a new {@link Eventual} with error handler applied */ public Eventual<T> onError(Function<Throwable, ? extends Eventual<? extends T>> errorHandler) { return fromMono(Mono.from(publisher) .onErrorResume(value -> Mono.from(errorHandler.apply(value)))); }