RxJS - Rewriting setInterval using observable
A small post on how we can rewrite setInterval using observable.
setInterval Example:
const intervalId = setInterval(() => console.log("Running setInterval"), 100);
setTimeout(() => clearInterval(intervalId), 1000);
setInterval example using observable:
const {interval} = require('rxjs');
const intervalObservable = interval(100);
const subscription = intervalObservable.subscribe(() => console.log("Running setInterval"));
setTimeout(() => subscription.unsubscribe(), 1000);