-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Reusing ConnectableObservable created using replay().autoConnect() #6227
Copy link
Copy link
Closed
Description
I was making a component to reduce parallel requests for a common resource by using replay(). In the following example:
val f = Flowable.fromCallable { "FOO" }.replay(10, TimeUnit.SECONDS).autoConnect()
f.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ println("Result 1 $it") },
{ println("Error 1 $it") },
{ println("Complete 1") } )
f.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ println("Result 2 $it") },
{ println("Error 2 $it") },
{ println("Complete 2") } )
Flowable.timer(11, TimeUnit.SECONDS)
.flatMap { f }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ println("Result 3 $it") },
{ println("Error 3 $it") },
{ println("Complete 3") } )This gives
Result 1 FOO
Complete 1
Result 2 FOO
Complete 2
Complete 3
How can retrigger original flowable if someone subscribes after 10 seconds?
Using RxJava 2.x
Reactions are currently unavailable