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

Improve CountUpTimer ticks precision #8058

Merged
merged 9 commits into from
Feb 6, 2023
Merged

Conversation

Florian14
Copy link
Contributor

@Florian14 Florian14 commented Feb 1, 2023

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

  • Improved the precision of the CountUpTimer tick notifications by removing the tickerFlow which was introducing delays between each notification and did not notify at the expected time
  • Removed the duplicated Clock and moved the existing one from vector module to core-utils

Motivation and context

Fix: #8012 (comment)

Screenshots / GIFs

Tests

  • Step 1
  • Step 2
  • Step ...

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

@Florian14 Florian14 requested a review from bmarty February 1, 2023 17:10
@Florian14 Florian14 added the Z-NextRelease For issues and PRs which should be included in the NextRelease. label Feb 2, 2023
Copy link
Member

@bmarty bmarty left a 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(
Copy link
Member

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.

Copy link
Contributor Author

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 }
Copy link
Member

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 :) ).

@Florian14
Copy link
Contributor Author

Added CountUpTimer.start(initialValue) and a reset of the elapsedTime to 0 in CountUpTimer.stop() to improve the CountUpTimer API which makes more sense imo

@sonarcloud
Copy link

sonarcloud bot commented Feb 6, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@Florian14 Florian14 merged commit fb4cceb into develop Feb 6, 2023
@Florian14 Florian14 deleted the misc/fre/count_up_timer branch February 6, 2023 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-NextRelease For issues and PRs which should be included in the NextRelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants