-
Notifications
You must be signed in to change notification settings - Fork 731
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
Improve CountUpTimer ticks precision #8058
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
import java.util.concurrent.atomic.AtomicLong | ||
|
||
@OptIn(kotlinx.coroutines.ExperimentalCoroutinesApi::class) | ||
class CountUpTimer(initialTime: Long = 0L, private val intervalInMs: Long = 1_000) { | ||
class CountUpTimer( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are not using tickerFlow
anymore, I think the @OptIn
can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
@Test | ||
fun `when pausing and resuming the timer, the timer ticks the right values at the right moments`() = runTest { | ||
every { fakeClock.epochMillis() } answers { currentTime } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively we could define a TestClock like this:
@OptIn(ExperimentalCoroutinesApi::class)
class TestClock(private val ts: TestScope) : Clock {
override fun epochMillis(): Long {
return ts.currentTime
}
}
(do not change, it's just to share my idea :) ).
Added |
SonarCloud Quality Gate failed. |
Type of change
Content
CountUpTimer
tick notifications by removing thetickerFlow
which was introducing delays between each notification and did not notify at the expected timeClock
and moved the existing one fromvector
module tocore-utils
Motivation and context
Fix: #8012 (comment)
Screenshots / GIFs
Tests
Tested devices
Checklist