I'm adding a stopwatch feature to my scoreboard timer component (by modifying the countdown clock I had previously). The stopwatch runs continuously, but would like it so that the seconds stop incrementing after 20 seconds (this.timePerQuestion).
Please could you see my code below and help me with this issue. Thank you.
stopwatch(): void {
this.start$ = this.timerService.start$;
this.reset$ = this.timerService.reset$;
this.stop$ = this.timerService.stop$;
this.time$ = concat(this.start$.pipe(first())).pipe(
switchMapTo(
timer(0, 1000).pipe(
scan((acc) => acc + 1, 0)
)
),
takeUntil(this.stop$.pipe(skip(1))),
repeatWhen(completeSubj =>
completeSubj.pipe(
switchMapTo(
this.start$.pipe(
skip(1),
first()
)
)
)
)
).pipe(tap((value: number) => this.timerService.setElapsed(value)));
}