Java Code Examples for io.reactivex.Flowable#subscribeWith()
The following examples show how to use
io.reactivex.Flowable#subscribeWith() .
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
Source File: ServerCalls.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Implements a unary → stream call as {@link Single} → {@link Flowable}, where the server responds with a * stream of messages. */ public static <TRequest, TResponse> void oneToMany( final TRequest request, final StreamObserver<TResponse> responseObserver, final Function<Single<TRequest>, Flowable<TResponse>> delegate) { try { final Single<TRequest> rxRequest = Single.just(request); final Flowable<TResponse> rxResponse = Preconditions.checkNotNull(delegate.apply(rxRequest)); final RxSubscriberAndServerProducer<TResponse> serverProducer = rxResponse.subscribeWith(new RxSubscriberAndServerProducer<TResponse>()); serverProducer.subscribe((ServerCallStreamObserver<TResponse>) responseObserver); } catch (Throwable throwable) { responseObserver.onError(prepareError(throwable)); } }
Example 2
Source File: RxBusBuilder.java From RxBus2 with Apache License 2.0 | 6 votes |
public <R> Disposable subscribe(DisposableSubscriber<R> subscriber, FlowableTransformer<T, R> transformer) { Flowable flowable = build(false); if (transformer != null) flowable = flowable.compose(transformer); Subscriber<R> actualSubscriber = subscriber; if (mQueuer != null && mQueueSubscriptionSafetyCheckEnabled) actualSubscriber = RxBusUtil.wrapSubscriber(subscriber, mQueuer); flowable = applySchedular(flowable); Disposable disposable = (DisposableSubscriber)flowable.subscribeWith(actualSubscriber); if (mBoundObject != null) RxDisposableManager.addDisposable(mBoundObject, disposable); return disposable; }
Example 3
Source File: ClientCalls.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Implements a stream → unary call as {@link Flowable} → {@link Single}, where the client transits a stream of * messages. */ @SuppressWarnings("unchecked") public static <TRequest, TResponse> Single<TResponse> manyToOne( final Flowable<TRequest> flowableSource, final Function<StreamObserver<TResponse>, StreamObserver<TRequest>> delegate, final CallOptions options) { try { final RxSubscriberAndClientProducer<TRequest> subscriberAndGRPCProducer = flowableSource.subscribeWith(new RxSubscriberAndClientProducer<TRequest>()); final RxClientStreamObserverAndPublisher<TResponse> observerAndPublisher = new RxClientStreamObserverAndPublisher<TResponse>( new com.salesforce.reactivegrpc.common.Consumer<CallStreamObserver<?>>() { @Override public void accept(CallStreamObserver<?> observer) { subscriberAndGRPCProducer.subscribe((CallStreamObserver<TRequest>) observer); } }, new Runnable() { @Override public void run() { subscriberAndGRPCProducer.cancel(); } } ); delegate.apply(observerAndPublisher); return Flowable.fromPublisher(observerAndPublisher) .singleOrError(); } catch (Throwable throwable) { return Single.error(throwable); } }
Example 4
Source File: ClientCalls.java From reactive-grpc with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Implements a bidirectional stream → stream call as {@link Flowable} → {@link Flowable}, where both the client * and the server independently stream to each other. */ @SuppressWarnings("unchecked") public static <TRequest, TResponse> Flowable<TResponse> manyToMany( final Flowable<TRequest> flowableSource, final Function<StreamObserver<TResponse>, StreamObserver<TRequest>> delegate, final CallOptions options) { final int prefetch = RxCallOptions.getPrefetch(options); final int lowTide = RxCallOptions.getLowTide(options); try { final RxSubscriberAndClientProducer<TRequest> subscriberAndGRPCProducer = flowableSource.subscribeWith(new RxSubscriberAndClientProducer<TRequest>()); final RxClientStreamObserverAndPublisher<TResponse> observerAndPublisher = new RxClientStreamObserverAndPublisher<TResponse>( new com.salesforce.reactivegrpc.common.Consumer<CallStreamObserver<?>>() { @Override public void accept(CallStreamObserver<?> observer) { subscriberAndGRPCProducer.subscribe((CallStreamObserver<TRequest>) observer); } }, new Runnable() { @Override public void run() { subscriberAndGRPCProducer.cancel(); } }, prefetch, lowTide); delegate.apply(observerAndPublisher); return Flowable.fromPublisher(observerAndPublisher); } catch (Throwable throwable) { return Flowable.error(throwable); } }