rxjs-examples icon indicating copy to clipboard operation
rxjs-examples copied to clipboard

Hi I found a bug in stop watch

Open ivanff opened this issue 2 years ago • 0 comments

https://stackblitz.com/edit/rxjs-stop-watch?file=index.ts

An excellent starting point, thank you, but if you reduce the interval to say 1 millisecond, then apparently due to the execution of javascript, the stopwatch does not work correctly, greatly underestimating the time.

I came across an operator that can partially fix this problem.

switchMap((state: State) => { if (state.count) { return interval( state.speed ).pipe( timeInterval(), tap((_) => { const value = _.interval / state.speed state.value += state.countup ? value : -value }), tap(_ => this.setValue(state.value)) ) } else { return NEVER } })

ivanff avatar Nov 08 '22 09:11 ivanff