rx.Emitter.BackpressureMode Java Examples
The following examples show how to use
rx.Emitter.BackpressureMode.
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: RxEventSources.java From mobius with Apache License 2.0 | 5 votes |
/** * Create an observable from the given event source. * * @param eventSource the eventSource you want to convert to an observable * @param <E> the event type * @return an Observable based on the provided event source */ public static <E> Observable<E> toObservable( final EventSource<E> eventSource, BackpressureMode backpressureMode) { checkNotNull(eventSource); checkNotNull(backpressureMode); return Observable.create( new Action1<Emitter<E>>() { @Override public void call(final Emitter<E> emitter) { final Disposable disposable = eventSource.subscribe( new Consumer<E>() { @Override public void accept(E value) { emitter.onNext(value); } }); emitter.setCancellation( new Cancellable() { @Override public void cancel() throws Exception { disposable.dispose(); } }); } }, backpressureMode); }
Example #2
Source File: KeyVaultFutures.java From azure-libraries-for-java with MIT License | 5 votes |
Observable<T> toObservable() { return Observable .create(new Action1<Emitter<List<TInner>>>() { @Override public void call(final Emitter<List<TInner>> emitter) { list(new ListOperationCallback<TInner>() { @Override public PagingBehavior progress(List<TInner> partial) { emitter.onNext(partial); return PagingBehavior.CONTINUE; } @Override public void success() { emitter.onCompleted(); } @Override public void failure(Throwable t) { emitter.onError(t); } }); } }, BackpressureMode.BUFFER) .flatMap(new Func1<List<TInner>, Observable<TInner>>() { @Override public Observable<TInner> call(List<TInner> secretItems) { return Observable.from(secretItems); } }).flatMap(new Func1<TInner, Observable<T>>() { @Override public Observable<T> call(TInner tInner) { return typeConvertAsync(tInner); } }); }
Example #3
Source File: KuduClient.java From azure-libraries-for-java with MIT License | 5 votes |
private Observable<String> streamFromBufferedSource(final BufferedSource source) { return Observable.create(new Action1<Emitter<String>>() { @Override public void call(Emitter<String> stringEmitter) { try { while (!source.exhausted()) { stringEmitter.onNext(source.readUtf8Line()); } stringEmitter.onCompleted(); } catch (IOException e) { stringEmitter.onError(e); } } }, BackpressureMode.BUFFER); }
Example #4
Source File: RxConnectables.java From mobius with Apache License 2.0 | 4 votes |
public static <I, O> Observable.Transformer<I, O> toTransformer( final Connectable<I, O> connectable, final BackpressureMode backpressureMode) { return new Observable.Transformer<I, O>() { @Override public Observable<O> call(final Observable<I> upstream) { return Observable.create( new Action1<Emitter<O>>() { @Override public void call(final Emitter<O> emitter) { Consumer<O> output = new Consumer<O>() { @Override public void accept(O value) { emitter.onNext(value); } }; final Connection<I> input = connectable.connect(output); final Subscription subscription = upstream.subscribe( new Action1<I>() { @Override public void call(I f) { input.accept(f); } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { emitter.onError(throwable); } }, new Action0() { @Override public void call() { emitter.onCompleted(); } }); emitter.setCancellation( new Cancellable() { @Override public void cancel() throws Exception { subscription.unsubscribe(); input.dispose(); } }); } }, backpressureMode); } }; }
Example #5
Source File: RxConnectables.java From mobius with Apache License 2.0 | 4 votes |
public static <I, O> Observable.Transformer<I, O> toTransformer( final Connectable<I, O> connectable) { return toTransformer(connectable, BackpressureMode.NONE); }
Example #6
Source File: RxStores.java From grox with Apache License 2.0 | 3 votes |
/** * Creates an observable of states out of a store. It is possible to call this method multiple * times on the same store. * * <p><em>Warning:</em> The created observable keeps a strong reference to {@code store}. * Unsubscribe to free this reference. * * @param store the store to observe states from. * @param <STATE> the class of the state. * @return an observable of the states. */ public static <STATE> Observable<STATE> states(Store<STATE> store) { if (store == null) { throw new IllegalArgumentException("Store is null"); } return Observable.create(new StoreOnSubscribe<>(store), BackpressureMode.ERROR); }