Reputation: 8550
Is it possible to cancel a single event in RxJava?
By that I mean something like this:
final protected PublishSubject<Object> subject = PublishSubject.create();
//...
subject.onNext(object);
//...
subject.cancel(object);
Upvotes: 1
Views: 229
Reputation: 23962
Short answer:
No.
Long answer:
It is not possible to cancel the event, but it is possible to unsubscribe from Observable
at the right time instead:
cancelEvents = BehaviourSubject.create();
// ...
subject
.takeUntil(cancelEvents)
.subscribe(...)
// ...
cancelEvents.onNext(someEvent);
Upvotes: 1