se.fortnox.reactivewizard.util.FluxRxConverter Maven / Gradle / Ivy
package se.fortnox.reactivewizard.util;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import rx.Observable;
import rx.RxReactiveStreams;
import rx.Single;
import java.util.function.Function;
import static java.util.Objects.requireNonNull;
public class FluxRxConverter {
public static final String OBSERVABLE_NULL_ERROR = "Observable to convert must not be null";
/**
* Convert Observable to Flux.
* Note that this method:
*
* - Does not preserve any decoration present on the Observable. For that purpose, use {@link #converterToFlux(Class)}.
*
*
* @param observable the Observable to convert
* @param type of the Observable
* @return the converted Flux
*/
public static Flux observableToFlux(Observable observable) {
requireNonNull(observable, OBSERVABLE_NULL_ERROR);
return Flux.from(RxReactiveStreams.toPublisher(observable));
}
/**
* Convert Observable to Mono.
* Note that this method:
*
* - Does not preserve any decoration present on the Observable.
* - Will only keep the first (or none, if empty) value emitted by the source Observable.
*
*
* @param observable the Observable to convert
* @param type of the Observable
* @return the converted Mono
*/
public static Mono observableToMono(Observable observable) {
requireNonNull(observable, OBSERVABLE_NULL_ERROR);
return Mono.from(RxReactiveStreams.toPublisher(observable));
}
/**
* Create converter from a reactive type to Flux, keeping any decoration present in the source object.
*
* @param returnType the return type
* @param the type of Flux
* @return the converter or null if unable to create converter
*/
public static Function
© 2015 - 2025 Weber Informatics LLC | Privacy Policy