RxJava: 2.1.2 Completable with andThen never completes
This test fails:
Completable.complete()
.andThen{ Completable.complete() }
.test()
.assertComplete()
However this one succeeds:
Completable.complete()
.test()
.assertComplete()
This one also succeeds:
Flowable.just("")
.flatMap { Flowable.just("") }
.test()
.assertComplete()
My understanding is that concating (which is what andThen does?) two completables which complete immediately should complete. I tried:
- using
awaitForTerminalEvent
but it just runs forever in the first case. .andThen{}
instead of.andThen{ Completable.complete() }
Completable.fromCallable
instead ofCompletable.complete()
or switching from aFlowable
toCompletable
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 4
- Comments: 15 (5 by maintainers)
Commits related to this issue
- Fix subsource not called after completable completes to clear cache - see https://github.com/ReactiveX/RxJava/issues/5551 — committed to ringoid/RingoidAndroidApp by orcchg 5 years ago
You want andThen(Completable.complete()). Note the use of parenthesis and not curly braces. The latter creates a lambda that doesn’t call its emitter.
On Sat, Aug 12, 2017, 11:30 AM Michał Klimczak notifications@github.com wrote:
Please be patient on StackOverflow (deleted) next time!
For one, you implemented
Completable
incorrectly and in a way most people don’t need to do it. UseCompletable.create()
instead. Second, you have to complete theCompletableObserver
, otherwiseandThen
won’t know to switch to the other source.This is a very silly api tbh, everyone I know was burned by this
Generally I am, but it honestly looked like an error to me, especially given the way flatMap and similar operators work for Flowable. Sorry!
@ericntd It’s not an issue with RxJava but how Kotlin trains you to use { } as the convenient lambda syntax. So RxJava 3 can’t help you solve this problem either.
@amanshuraikwar That is how it is supposed to be done. How is it not working. Could you write an unit test demonstrating your problem?
@micHar I agree with you, the .andThen{} is equivalent to .doOnComplete{}, isn’t it? I mean what would be the use case that only .andThen{} solve ?