Implement pause and resume feature correctly through RxJS

InstructorAndré Staltz

Share this video with your friends

Send Tweet

Eventually you will feel the need for pausing the observation of an Observable and resuming it later. In this lesson we will learn about use cases where pausing is possible, and what to do when pausing is impossible.

NWT
~ 7 years ago

That's actually not fully true. You can create your observable, make custom setInterval inside which will call .next(). And submit pause / resume which will make clearInterval / run interval again.

Mykolas Mikelevicius
~ 7 years ago

We can't really pause without custom implementation of observable, but if we really need to get interval values from that "pause" moment, we could save the last value and increment respectively. Another approach, which could work in some cases is just ignoring interval values when it is "paused" using windowToggle like here: https://egghead.io/lessons/rxjs-split-an-rxjs-observable-conditionally-with-windowtoggle.