I\'m trying to create a Timer
that calls an API call
every 10 seconds, I\'m using setTimeOut
but the thing is that it becomes an infin
from RxJS 6+ you just use interval.
import { interval } from 'rxjs';
//in 10 seconds do something
interval(10000).subscribe(x => {
this.myFunctionThatDoesStuff();
});
you can use Subscription
with the interval.
import { interval, Subscription} from 'rxjs';
export class intervalDemo{
mySubscription: Subscription
constructor(){
this.mySubscription= interval(5000).subscribe((x =>{
this.doStuff();
}));
}
doStuff(){
//doing stuff with unsubscribe at end to only run once
this.failedRequestSub.unsubscribe();
}
}