Reputation: 547
Observable
.interval(2, TimeUnit.SECONDS)
.switchMap(integer ->
Observable
.just(integer * 2)
.delay(5,SECONDS))
.subscribe(integer -> { System.out.println(integer);});
As I understood, after switch map we should subscribe to last created observable, so I expect output "8" after 20 seconds, but it waits forever
Upvotes: 1
Views: 2243
Reputation: 8227
The operation of switchMap()
operator goes as follows:
The result is that the delayed observable will never emit anything because it will be unsubscribed every 2 seconds.
You will need to use flatMap()
operator instead, which will not unsubscribe on each emitted value.
Upvotes: 1