What is the cleanest way to perform a side effect when posting the latest subscription to an RxJS Observable? This can happen before the Observable completes .
Let's say I need a function that returns an Observable that emits resource changes. I would like to perform a cleanup operation when all subscriptions have been deleted.
var observable = streamResourceChanges(resource); var subscription1 = observable.subscribe(observer1); var subscription2 = observable.subscribe(observer2);
The only thing I found to determine the disposition recycling action is to use Rx.Observable.create . Last deletion can be controlled by sharing a subscription, such as Observable.prototype.singleInstance() .
For instance:
function streamResourceChanges(resource) { return Rx.Observable.create(function(observer) {
Is there an easier way to define a side effect for deleting a subscription similar to doOnNext , doOnCompleted or doOnError ?
var withCleanup = withoutCleanup.doOnDispose(function() {
Kimmo source share