Skip to content

Instantly share code, notes, and snippets.

@nlharri
Last active November 19, 2018 11:12
Show Gist options
  • Save nlharri/03ba1aa6c8a0c294b4d35a0fb14ce8d9 to your computer and use it in GitHub Desktop.
Save nlharri/03ba1aa6c8a0c294b4d35a0fb14ce8d9 to your computer and use it in GitHub Desktop.
RxJS Tutorial - Unsubscribe
const { interval } = require('rxjs')
const { throttleTime } = require('rxjs/operators');
// emit value every 500 millisecond (0.5 second)
const myObserver = interval(500);
const myThrottledObserver = myObserver.pipe(throttleTime(1000));
const myDisposable = myThrottledObserver.subscribe(val => console.log(val));
// unsubscribe after 10 seconds
setTimeout(() => {
myDisposable.unsubscribe();
}, 10000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment