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

The pausable() observables

The last operator to implement the lossy technique to deal with backpressure is the pausable() operator. This operator returns a pausable() observable so we can pause it (and discard all the data while paused) and resume it when we are ready to accept more data.

The pausable() method has the following signature:

observable.pausable(); 

As you can see, it doesn't accept any parameter.

We can see an example of the usage of this operator in the following code:

var pausableObservable = Rx.Observable     .interval(50)     .pausable(); pausableObservable.subscribe((i)=>console.log(i)); pausableObservable.pause(); setTimeout(()=>{     pausableObservable.resume(); },2000); 

If you run this code, you will see the following output ...

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