Eventually you'll feel the need for pausing the observation of a Observable and resuming it later. In this lesson we'll learn about the use cases where pausing are possible, and what does when pausing is impossible.
Constresume$ =NewRx.subject ();Constres$ =resume$. Switchmap (Resume=Resume?Rx.Observable.interval ( -): Rx.Observable.empty ()). Do(x = Console.log ('Request It!'+x). Switchmap (EV=Rx.Observable.ajax ({URL:'HTTPS://JSONPLACEHOLDER.TYPICODE.COM/USERS/1', Method:'GET', })); Res$.subscribe (function (data) {Console.log (data.response);}); Resume$.next (false); SetTimeout (()= Resume$.next (true), -); SetTimeout (()= Resume$.next (false), the);
Here use
Rx.Observable.empty ()
Inside Switchmap (), it means if code goes to empty () and then the rest of code:
. Do (). Switchmap ()
Won ' t run.
If just subscribe, it trigger complete function:
var source = Rx.Observable.empty (); var subscription = Source.subscribe ( function (x) { console.log ('Next:%s ', x); }, function (err) { console.log ('Error:%s ', err); }, function () { console.log ('completed' ); }); // = Completed
[RxJS] Implement pause and resume feature correctly through RxJS