Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi I found a bug in stop watch #2

Open
ivanff opened this issue Nov 8, 2022 · 0 comments
Open

Hi I found a bug in stop watch #2

ivanff opened this issue Nov 8, 2022 · 0 comments

Comments

@ivanff
Copy link

ivanff commented Nov 8, 2022

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
}
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant