Skip to content

Instantly share code, notes, and snippets.

@thcolin
Created April 14, 2017 13:00
Show Gist options
  • Save thcolin/e0092b226cd33c4cd418cbc59eaaaf08 to your computer and use it in GitHub Desktop.
Save thcolin/e0092b226cd33c4cd418cbc59eaaaf08 to your computer and use it in GitHub Desktop.
RxJS pauseable
import Rx from 'rxjs/Rx';
var pauser = new Rx.Subject();
var source = Rx.Observable.interval(1000);
var pauseable = pauser.switchMap(paused => paused ? Rx.Observable.never() : source);
pauseable.subscribe(n => console.log('next', n), e => console.log('error', e), c => console.log('complete', c));
pauser.next(false);
setTimeout(() => pauser.next(true), 5000);
setTimeout(() => pauser.next(false), 10000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment