RxGo icon indicating copy to clipboard operation
RxGo copied to clipboard

How to stop a Interval observable?

Open Robert-M-Muench opened this issue 4 years ago • 1 comments

I'm missing a close, unsubscribe, dispose, etc. function? How am I supposed to stop it?

Robert-M-Muench avatar Dec 05 '20 15:12 Robert-M-Muench

I think you're going to need to use Connect so that it returns to you a Context and a Disposable. See observable_operator.go:596.

// Connect instructs a connectable Observable to begin emitting items to its subscribers.
func (o *ObservableImpl) Connect(ctx context.Context) (context.Context, Disposable) {
	ctx, cancel := context.WithCancel(ctx)
	o.Observe(WithContext(ctx), connect())
	return ctx, Disposable(cancel)
}

Once you have a Disposable, you have a cancel func to dispose of the subscription. See types.go:41.

	// Disposable is a function to be called in order to dispose a subscription.
	Disposable context.CancelFunc

darrensapalo avatar Dec 05 '20 17:12 darrensapalo