Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RX Subject<T> How To Cancel a Subscription

I have a service that returns a Subject<T> and consumer is subscribing to it. How would I cancel an existing subscription and dispose it?

like image 494
Andy Avatar asked Apr 06 '11 17:04

Andy


People also ask

How do I unsubscribe from observable Android?

Show activity on this post. When an Observable issues an OnError or OnComplete notification to its observers, this ends the subscription. Observers do not need to issue an Unsubscribe notification to end subscriptions that are ended by the Observable in this way.


1 Answers

When you call Subscribe() on your Subject<T>, it returns an IDisposable. Just call Dispose() on the returned handle, and it will cancel the subscription.

like image 187
Reed Copsey Avatar answered Oct 17 '22 17:10

Reed Copsey