rx-java

RxAndroidBle keeping a persistant connection + Write/Notification handling

我们两清 提交于 2019-12-28 06:33:48
问题 I am building an Android application that has specific requirements regarding Bluetooth Low Energy. I need to write to a Write-only characteristic and receive responses on a separate notification characteristic, and I need to do it in many, many activities. Is there a Rx way to send a request on the 1st characteristic, wait for the answer on the second one, then proceed to another request? Also, to share my instance of RxAndroidBle I thought about doing some sort of BleManager Singleton where

RxJava and parallel execution of observer code

社会主义新天地 提交于 2019-12-28 05:07:20
问题 I am having the following code using RxJava Observable api : Observable<Info> observable = fileProcessor.processFileObservable(processedFile.getAbsolutePath()); observable .buffer(10000) .observeOn(Schedulers.computation()) .subscribe(recordInfo -> { _logger.info("Running stage2 on thread with id : " + Thread.currentThread().getId()); for(Info info : recordInfo) { // some I/O operation logic } }, exception -> { }, () -> { }); My expectation was that the observation code i.e. code inside the

RxJava delay for each item of list emitted

廉价感情. 提交于 2019-12-28 01:50:34
问题 I'm struggling to implement something I assumed would be fairly simple in Rx. I have a list of items, and I want to have each item emitted with a delay. It seems the Rx delay() operator just shifts the emission of all items by the specified delay, not each individual item. Here's some testing code. It groups items in a list. Each group should then have a delay applied before being emitted. Observable.range(1, 5) .groupBy(n -> n % 5) .flatMap(g -> g.toList()) .delay(50, TimeUnit.MILLISECONDS)

How to wrap a cold observable (ReactiveX / RxJava) that always return the last result + allow refresh

江枫思渺然 提交于 2019-12-25 21:22:46
问题 I'm trying to rely on Reactive Programming to share the result of an http call with many subscribers. At the same time I want to be able to perform the call again (refresh). I start with a cold Observable that perform the http call and then immediately complete. I want to wrap it to obtain an hot observable that work like this: every subscriber should always receive the last event (if any) when subscribing and every other event until unsubscribed. I should have a way (external to that

Retry network calls in RxJava

久未见 提交于 2019-12-25 16:45:09
问题 How to make retry network calls when network errors appear with rxJava in Android. Here is my rxJave code: RxTextView.textChanges(searchInput) .debounce(500, TimeUnit.MILLISECONDS) .map(CharSequence::toString) .filter(s -> !s.isEmpty()) .subscribeOn(AndroidSchedulers.mainThread()) .observeOn(Schedulers.io()) .switchMap(query -> getTypedPlaces(query)) .observeOn(AndroidSchedulers.mainThread()) .subscribe(results -> showResult(results)); It works very well but I need to retry network request

RxJava Observable.create wrapping observable subscriptions

亡梦爱人 提交于 2019-12-25 09:27:31
问题 I used Observable.create so I could notify the subscriber when certain data was available. I am a little uncertain of subscribing to observables inside of my create method. Are these nested subscriptions going to give me any sort of issue? I'm not completely familiar with creating observables using Observable.create so I wanted to make sure I'm not doing anything out of the ordinary or misusing it. Thank you in advance! abstract class NetworkResource<ApiType, DbType> constructor(private val

Null handling in rx-java2 flatMap

删除回忆录丶 提交于 2019-12-25 08:59:24
问题 As explained in the docs RxJava 2.x no longer accepts null values. So it is not surprising that both of the following two lines terminate with onError called: Observable.fromCallable(() -> null); Observable.just(1).flatMap(i -> Observable.error(new RuntimeException())); what is unclear is why Observable.just(1).flatMap(i -> Observable.fromCallable(() -> null)) terminates with success and no items emitted. It seams reasonable to expect for it behave in the same fashion as Observable.error I

RxJava 2: always unsubscribe on the .subscribeOn(..) scheduler?

白昼怎懂夜的黑 提交于 2019-12-25 08:15:42
问题 I have an Observable<String> that performs some work. After its done, it closes its connections (via .setDisposable(Disposables.fromAction(logic*); . Trouble is, I need this close action to be performed on the same scheduler as the actual workload. Is it possible? How? I dont want to force the Observable to perform on a given scheduler, e.g. myObservable.subscribeOn(x).unsubscribeOn(x); ; 回答1: You need a single threaded scheduler for that to work and you can get one via Schedulers.from

RxJava retryWhen operator is not working as expected

只愿长相守 提交于 2019-12-25 08:14:02
问题 Suppose I have List<CharSequence> observableList , which contains random CharSequence 's which have length from 1 to 10. I have such Observable : Observable.from(observableList) .flatMap(new Func1<CharSequence, Observable<CharSequence>>() { @Override public Observable<CharSequence> call(CharSequence charSequence) { if (charSequence.length() == 1) { return Observable.error(new RuntimeException("Too short")); } else { return Observable.just(charSequence); } } }).retryWhen(new Func1<Observable<?

RxJava - Merged Observable that accepts more Observables at any time?

偶尔善良 提交于 2019-12-25 08:08:46
问题 I am encountering a need for an Observable implementation that holds one or more Observables and merges them. But here is the kicker: I want to add more Observables to be merged at any time, and I guess it might as well support removing them too. For it to be truly effective, all Subscribers must receive notifications from new Observables that are added post-subscription. Unless all the merged Observables are cold and call onComplete() , then I guess it is okay to let the subscriptions