I am implementing a countdown functionality with the following code:
userClick=new Subject()
resetCountdown(){this.userClick.next()}
setCountDown() {
let counter = 5;
let tick = 1000;
this.countDown = timer(0, tick)
.pipe(
take(counter),
map(() => --counter),
takeUntil(this.userClick),
finalize(() => {
if (this.currentQuestionNumber < this.questionsToAsk)
this.showNextQuestion();
else {
this.endQuiz();
}
})
);
}
Now, I have a requirement that when takeUntil(this.userClick)
interrupts the countdown, I do not want finalize
to be executed. Is there any way to achieve this? The desired behavior is for finalize
to only execute when the countdown reaches 0
without being interrupted by takeUntil
.