Thanks for a great implementation of ReactiveX!
We have several case where we're trying to implement the following pattern:
1. User clicks "Save Foo". If a previous save was still pending (e.g., never finished) it's aborted and previous subscription released.
2. Foo is asynchronously sent to database to be saved
3. A "Foo saved" message is shown once the operation completes and the screen is closed.
To do this, we have an `Observable<Foo> saveFooClicks` in our view, a method `Completable saveFoo(Foo)` in our data store, and the following code to set up the stream and subscription:
disposeOnClear(
saveFooClicks
.switchMap(
foo ->
saveFoo(foo)
.doOnComplete(() -> onSaveFoo(foo))
.onErrorComplete()
.toObservable())
.subscribe());
Note that we use `onErrorComplete()` to avoid breaking the upstream Observable in case `saveFoo()`’s Completable terminates with an error. We could also wrap the potential errors in another object and propagate them to the outer stream, but since this is all being done in the same context, that seems unnecessary.
Is there a more idiomatic, intuitive way of doing this? Or are we simply holding it wrong?
Thanks in advance!
-Gino