Java Code Examples for io.reactivex.Single#flatMapPublisher()

The following examples show how to use io.reactivex.Single#flatMapPublisher() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
 * Implements a unary → stream call as {@link Single} → {@link Flowable}, where the server responds with a
 * stream of messages.
public static <TRequest, TResponse> Flowable<TResponse> oneToMany(
        final Single<TRequest> rxRequest,
        final BiConsumer<TRequest, StreamObserver<TResponse>> delegate,
        final CallOptions options) {
    try {

        final int prefetch = RxCallOptions.getPrefetch(options);
        final int lowTide = RxCallOptions.getLowTide(options);

        return rxRequest
                .flatMapPublisher(new io.reactivex.functions.Function<TRequest, Publisher<? extends TResponse>>() {
                    public Publisher<? extends TResponse> apply(TRequest request) {
                        final RxClientStreamObserverAndPublisher<TResponse> consumerStreamObserver =
                            new RxClientStreamObserverAndPublisher<TResponse>(null, null, prefetch, lowTide);

                        delegate.accept(request, consumerStreamObserver);

                        return consumerStreamObserver;
    } catch (Throwable throwable) {
        return Flowable.error(throwable);
Example 2
public static void readFile2(File file) {
    Single<BufferedReader> readerSingle = Single.just(file) //1
            .observeOn( //2
            .map(BufferedReader::new); //3
    Flowable<String> flowable = readerSingle.flatMapPublisher(reader -> //4
            Flowable.fromIterable( //5
                    () -> Stream.generate(readLineSupplier(reader)).iterator()
            ).takeWhile(line -> !"EOF".equals(line))); //6
            .doOnNext(it -> System.out.println("thread="
                    + Thread.currentThread().getName())) //7
            .doOnError(ex -> ex.printStackTrace())
            .blockingSubscribe(System.out::println); //8
Example 3
Source Project: cyclops   File:    License: Apache License 2.0 5 votes vote down vote up
public static <T> Flowable<Single<T>> sequence(final Publisher<? extends Flowable<T>> fts) {

        io.reactivex.functions.BiFunction<Flowable<Single<T>>,Flowable<T>,Flowable<Single<T>>> combineToStream = (acc,next) ->Flowable.merge(acc,;
        Single<Flowable<Single<T>>> x = Flowable.fromPublisher(fts).reduce(Flowable.empty(), combineToStream);
        Flowable<Flowable<Single<T>>> r = x.flatMapPublisher(Flowable::just);
        return r.flatMap(i->i);