I have a unique service that automatically calls a method every 30 seconds. There is also a button that allows the user to reset the timer, preventing the method from being called for another 30 seconds. How can I make sure that the method does not get called within the interval if the button is clicked?
COMPONENT
constructor(private customService: CustomService) {
this.customService.initiate();
}
resetTimer(): void {
this.customService.resetTimer();
}
SERVICE
initiate(): void {
timer(0, 30000).subscribe(() => this.refresh());
}
resetTimer(): void {
// Need guidance here
}
Currently, my component initializes the timer by calling the initiate() method in its constructor. The idea is that by calling resetTimer() in the component's HTML, it will eventually call the resetTimer() method in the service to restart the timer. Can you assist me with achieving this functionality?
Appreciate your help!