rx-java2

Mocking a http response using vert.x rxjava2 and Mockito

余生长醉 提交于 2020-02-28 23:18:18
问题 I'm playing with the rxjava vert.x (ver. 3.8.4) WebClient. My client will call some services so, by Mockito (ver. 3.2.4) I'm testing how it should handle an error. Here is how I mock the service's response: ... JsonObject jsonResponse = new JsonObject(); HttpResponse<Buffer> httpResponse = Mockito.mock(HttpResponse.class); Mockito.when(httpResponse.statusCode()).thenReturn(500); Mockito.when(httpResponse.bodyAsJsonObject()).thenReturn(jsonResponse); HttpRequest<Buffer> httpRequest = Mockito

Do I have to unsubscribe from completed observable?

女生的网名这么多〃 提交于 2020-01-30 14:30:11
问题 If an observable completes, do I still have to unsubscribe / dispose (in RxJava2) the observable to remove the Observer (prevent memory leaks) or is this handled internally by RxJava once a onComplete or onError event occurs? what about other types like Single , Completable , Flowable etc. 回答1: Yes you are correct. After a stream is terminated ( onComplete / onError has been called ), subscriber unsubscribes automatically. You should be able to test these behaviors using isUnsubscribed()

Wrapping event listeners in Observables

 ̄綄美尐妖づ 提交于 2020-01-25 21:41:30
问题 I've seen a lot of examples of how to turn finite things like arrays or Iterable s into Observable s, but I'm not sure I understand how to make an Observable out of something live and effectively unbounded like an event receiver. I studied the RxJava2 docs and came up with this, using an Android LocationListener as an example. Is there a simpler and/or more correct way to do this? I'm aware of the "RxBus" concept, but it seems like a way of clinging to the old event bus paradigm. final

Writing multiple commands to characteristic

拟墨画扇 提交于 2020-01-25 09:02:04
问题 I am just discovering rxandroidble and can reliably send a single command to the BLE device after connection However I am struggling to find the best way to write a chain of commands, ie if I have a series of 3 commands that need to be sent Of course this can be done by nesting the sends, but Im sure there is a better approach!! Single command send code is rxBleMainConection.writeCharacteristic(COMS_WRITE_CHAR_UUID,bytes).toObservable() .subscribe( characteristicValue -> { // Written

Avoiding same-pool deadlocks when using Flowable in Reactive Extensions

那年仲夏 提交于 2020-01-25 08:58:45
问题 While subscribing to a Reactive Extensions Flowable stream, I noticed the stream halts/hangs (no more future items are emitted, and no error is returned) after 128 items have been returned. val download: Flowable<DownloadedRecord> = sensor.downloadRecords() download .doOnComplete { Log.i( "TEST", "Finished!" ) } .subscribe( { record -> Log.i( "TEST", "Got record: ${record.record.id}; left: ${record.recordsLeft}" ) }, { error -> Log.i( "TEST", "Error while downloading records: $error" ) } )

RetryWhen is giving some issues when using with Single

孤街醉人 提交于 2020-01-24 20:41:06
问题 I am trying to hit an API call using retrofit and receive the response from the call. I am using the Single of Rxjava to get the response. What I need to do is that a retry if the call fails. I have gone through lots of examples but it seems none could have been a help (Also because of my limited knowledge on RXjava and Kotlin). Below is the function which does the call and the retryWhen function I wrote override fun fetchMessage(southDataModel: SouthDataModel): Single<ArrayList

RxJava - Mapping a result of list to another list

妖精的绣舞 提交于 2020-01-24 19:25:07
问题 I want to convert every object in my list to an another object. But in doing so my code stucks in converting them back to List override fun myFunction(): LiveData<MutableList<MyModel>> { return mySdk .getAllElements() // Returns Flowable<List<CustomObject>> .flatMap { Flowable.fromIterable(it) } .map {MyModel(it.name!!, it.phoneNumber!!) } .toList() //Debugger does not enter here .toFlowable() .onErrorReturn { Collections.emptyList() } .subscribeOn(Schedulers.io()) .to {

Does take(1) stop the upstream flowable doing work?

梦想与她 提交于 2020-01-16 09:41:10
问题 Let's assume we have some Flowable that looks like: val exampleFlowable = Flowable.create<Int>({ emitter -> while (true) { Thread.sleep(TimeUnit.SECONDS.toMillis(1)) emitter.onNext(1) } }, BackpressureStrategy.LATEST) .subscribeOn(Schedulers.io()) And then I call take(1) on it and subscribe to it like so (notice, disposing of the disposable in the subscribe block): var disposable: Disposable? = null disposable = exampleFlowable.take(1) .observeOn(AndroidSchedulers.mainThread()) .subscribe({

Does take(1) stop the upstream flowable doing work?

主宰稳场 提交于 2020-01-16 09:41:10
问题 Let's assume we have some Flowable that looks like: val exampleFlowable = Flowable.create<Int>({ emitter -> while (true) { Thread.sleep(TimeUnit.SECONDS.toMillis(1)) emitter.onNext(1) } }, BackpressureStrategy.LATEST) .subscribeOn(Schedulers.io()) And then I call take(1) on it and subscribe to it like so (notice, disposing of the disposable in the subscribe block): var disposable: Disposable? = null disposable = exampleFlowable.take(1) .observeOn(AndroidSchedulers.mainThread()) .subscribe({

RxJava 1 and RxJava 2 in the same project [duplicate]

╄→尐↘猪︶ㄣ 提交于 2020-01-11 11:03:54
问题 This question already has answers here : How to resolve Duplicate files copied in APK META-INF/rxjava.properties (7 answers) Closed 2 years ago . Our project uses RxJava 1: compile 'io.reactivex:rxjava:1.1.6' There is a library we use that uses RxJava 2 internally: compile 'io.reactivex.rxjava2:rxjava:2.0.9' When I do ./gradlew assembleDebug I get this error: com.android.build.api.transform.TransformException:com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK