Skip to content

Debounce operator not working as expected ?? #1434

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

Closed
shakil807g opened this issue Aug 11, 2019 · 2 comments
Closed

Debounce operator not working as expected ?? #1434

shakil807g opened this issue Aug 11, 2019 · 2 comments
Assignees
Labels
docs KDoc and API reference flow

Comments

@shakil807g
Copy link

      fun main() = runBlocking<Unit> {
         flow {
         emit(1)
         delay(99)
         emit(2)
         delay(99)
         emit(3)
         delay(1001)
         emit(4)
         delay(1001)
         emit(5)
  }.debounce(1000).collect {
         println(it)   // print  3, 5
 }

Above code print 3, 5
I expected it to print 3, 4, 5

@shakil807g
Copy link
Author

I found out there was a mistake in flow docs i change it to below and works fine

    fun main() = runBlocking<Unit> {
     flow {
     emit(1)
     delay(99)
     emit(2)
     delay(99)
     emit(3)
     delay(1001)
     emit(4)
     delay(1002)   ------->  increase 1 millisecond
     emit(5)
  }.debounce(1000).collect {
       println(it)   // print  3, 4, 5
 }

@qwwdfsad qwwdfsad added docs KDoc and API reference flow labels Aug 12, 2019
@qwwdfsad
Copy link
Member

Hi, thanks for the report.
The given example exposes the semantics of the method properly but fails in reality due to clock inaccuracy. I will adjust it to work on the default clocks as well

@qwwdfsad qwwdfsad self-assigned this Aug 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs KDoc and API reference flow
Projects
None yet
Development

No branches or pull requests

2 participants