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:
awaitForTerminalEvent but it just runs forever in the first case..andThen{} instead of .andThen{ Completable.complete() }Completable.fromCallable instead of Completable.complete() or switching from a Flowable to CompletableYou 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:
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 of Completable.complete() or
switching from a Flowable to Completable—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/ReactiveX/RxJava/issues/5551, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEbqMY0_Tox59wudzvNRhY1aL1URWks5sXe8mgaJpZM4O1fDE
.
So simple. Thanks!
Please be patient on StackOverflow (deleted) next time!
Generally I am, but it honestly looked like an error to me, especially given the way flatMap and similar operators work for Flowable. Sorry!
@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 ?
I am having a similar problem:
someCompletable().andThen(someObservable()).subscribe{...}
my someObservable() is never being called. Please help! I am new to Rx.
On a similar note, how can I sequence an Observable after a Completable. Is that even possible?
@amanshuraikwar That is how it is supposed to be done. How is it not working. Could you write an unit test demonstrating your problem?
Here is how I am using it:
Observable<Integer> observable = Observable.just(1).doOnSubscribe(disposable -> System.out.println("observable-subscribed"));
Completable completable = new Completable() {
@Override
protected void subscribeActual(CompletableObserver s) {
System.out.println("completable-subscribed");
}
};
completable
.andThen(observable)
.subscribe(integer -> System.out.println("emitted:"+integer));
And this is my output:
completable-subscribed
The observable is not even being subscribed. What am I doing wrong?
For one, you implemented Completable incorrectly and in a way most people don't need to do it. Use Completable.create() instead. Second, you have to complete the CompletableObserver, otherwise andThen won't know to switch to the other source.
Completable completable = Completable.create(emitter -> {
emitter.onComplete();
});
completable
.andThen(observable)
.subscribe(integer -> System.out.println("emitted:"+integer));
@akarnokd It works now, I was not completing the Completable. Thanks for your help! I really appreciate it.
This is definitely frustrating issue for beginners. I think it's good idea to do something to warn on incorrect usage.
This is a very silly api tbh, everyone I know was burned by this
Most helpful comment
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: