Questions tagged [rx-java]

RxJava – Reactive Extensions for the JVM – a library for composing asynchronous and event-based programs using observable sequences for the Java VM.

RxJava is a Java implementation of Reactive Extensions. Android-specific support for RxJava is provided by .

The main goals of RxJava

  • Stay true to the principles and concepts behind the original implementation while adjusting to the naming conventions and idioms of Java
  • All contracts of Rx should be the same target - the JVM
  • JVM-based languages supported (beyond Java itself) include , , , and
  • Support Java 6+

The library is open sourced under Apache 2.0 license.

References

6958 questions
29
votes
1 answer

How does RxJava doOnError and onErrorReturn work?

I made these unit tests, and the outcome is not what I expected at all: // This one outputs "subscribe.onError" @Test public void observable_doOnError_subscribingToError() throws InterruptedException { Observable obs =…
Nilzor
  • 18,082
  • 22
  • 100
  • 167
29
votes
2 answers

How to handle rotation with Retrofit and RxJava/RxAndroid in Activity?

I read here that we can use some global cache in order to handle rotation. You can prevent this by using the cache or replay Observable operators, while making sure the Observable somehow survives the Activity life-cycle (for instance, by storing…
DeniSHow
  • 1,394
  • 1
  • 18
  • 30
28
votes
3 answers

What does the term "backpressure" mean in Rxjava?

I am a beginner of RxJava and I am curious about the meaning of "backpressure". Does it mean that the producer puts pressure behind the consumer's back? Or does it mean that consumers are putting pressure on producers? (Pressure in opposite…
ohlab
  • 467
  • 5
  • 7
28
votes
3 answers

Kotlin and RxJava - Why is my Single.zip() not compiling?

I'm going a little crazy here. I'm trying to create an Observable extension function (against RxJava 2.x) to emit the average of the emissions, but I'm getting a compile error with the Single.zip() function. Does anybody have any ideas…
tmn
  • 11,121
  • 15
  • 56
  • 112
28
votes
1 answer

How to handle exceptions thrown by observer's onNext in RxJava?

Consider the following example: Observable.range(1, 10).subscribe(i -> { System.out.println(i); if (i == 5) { throw new RuntimeException("oops!"); } }, Throwable::printStackTrace); This outputs numbers from 1 to 5 and then…
izstas
  • 5,004
  • 3
  • 42
  • 56
27
votes
4 answers

Best practice for handling onError and continuing processing

I am new to RxJava but I am integrating it into a project that I am working on to help me learn it. I have run into a question about best practices. I have a question about how to handle onError from preventing the stopping of the Observable…
Alex Beggs
  • 1,187
  • 2
  • 11
  • 17
26
votes
1 answer

How does backpressure work in Project Reactor?

I've been working in Spring Reactor and had some previous testing that made me wonder how Fluxes handle backpressure by default. I know that onBackpressureBuffer and such exist, and I have also read that RxJava defaults to unbounded until you define…
James Gan
  • 407
  • 1
  • 6
  • 11
26
votes
2 answers

Chain two retrofit observables w/ RxJava

I want to execute 2 network calls one after another. Both network calls return Observable. Second call uses data from successful result of the first call, method in successful result of second call uses data from both successful result of the first…
localhost
  • 5,568
  • 1
  • 33
  • 53
26
votes
3 answers

RxJava vs Java 8 Parallelism Stream

What are all the similarities and diferences between them, It looks like Java Parallel Stream has some of the element available in RXJava, is that right?
Mohan Narayanaswamy
  • 2,149
  • 6
  • 33
  • 40
25
votes
2 answers

Is it correct to convert a CompletableFuture> to a Publisher?

To allow multiple iterations on the resulting stream from a CompletableFuture> I am considering one of the following approaches: Convert the resulting future to CompletableFuture> through: teams.thenApply(st ->…
Miguel Gamboa
  • 8,855
  • 7
  • 47
  • 94
25
votes
3 answers

Retrofit and RxJava: How to combine two requests and get access to both results?

I need to make two requests for services and combine it results: ServiceA() => [{"id":1,"name":"title"},{"id":1,"name":"title"}] ServiceB(id) => {"field":"value","field1":"value"} Currently, I have managed to combine the results, but I need to…
David Hackro
  • 3,652
  • 6
  • 41
  • 61
25
votes
4 answers

How to create Observable from function?

I want to call a function (synchronously) and then use its return value as an initial emission (subsequently chaining some other operators on the resulting observable). I want to invoke this function during subscription, so I can't just use…
Titan
  • 2,875
  • 5
  • 23
  • 34
25
votes
1 answer

Periodic HTTP Requests Using RxJava and Retrofit

Is it possible to use RxJava/RxAndroid and Retrofit to perform periodic http requests to update data every x seconds? Currently I am using an IntentService and Recursive Handler/Runnable that fires every x seconds. I'd like to know if I could…
Jeremy Lyman
  • 3,084
  • 1
  • 27
  • 35
24
votes
3 answers

Navigation with MVVM android

I have an app using Androids ViewModel class and Navigation Component for navigating between fragments. How would I handle navigation from the ViewModel? I am using RxJava and I was thinking of having the Fragments listen for navigation events and…
24
votes
2 answers

Rx 2 Android what is better Single or Observable for api calls?

when we use retrofit2 for doing API rest calls with Rx, What is the best approach to use, Single or Observable? public interface ApiService{ Single getDataFromServer(); Observable getDataFromServer(); }
Jose M Lechon
  • 5,766
  • 6
  • 44
  • 60