O'Reilly logo

Mastering Reactive JavaScript by Erich de Souza Oliveira

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

RxJS Disposable

The Disposable class gives us a method to release allocated resources (database connections, file handlers, and so on). We can do this by calling the dispose() method  of this object.

In this section, we will use the dispose() method to unsubscribe from an observable.

To create a Disposable, we can use the create() function from Rx.Disposable:

var disposable = Rx.Disposable         .create(()=>console.log('Releasing allocated resources')); disposable.dispose(); 

If you run this code, it will print the following message in your console:

    Releasing allocated resources

As discussed earlier in this chapter, we can call the dispose() method to unsubscribe from an observable. In some cases, we can even define a Disposable to be used ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required