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

Debounce keeps emitting values even though debounced publisher is not publishing #46

Closed
jakobmygind opened this issue Nov 7, 2019 · 6 comments · Fixed by #47
Closed
Labels
bug Something isn't working

Comments

@jakobmygind
Copy link

Debounce seems to get into an endless loop emitting last received value.
This code:

 let pub = PassthroughSubject<Int, Never>()
        
        pub
            .debounce(for: 1.0, scheduler: DispatchQueue.main.cx)
            .sink(receiveValue: {
                print("received: \($0) at: \(Date())")
            })
            .store(in: &subscribers)
        
        (0...10).forEach(pub.send)

Gives this result:

received: 10 at: 2019-11-07 10:16:58 +0000
received: 10 at: 2019-11-07 10:16:59 +0000
received: 10 at: 2019-11-07 10:17:00 +0000
received: 10 at: 2019-11-07 10:17:01 +0000
received: 10 at: 2019-11-07 10:17:02 +0000
received: 10 at: 2019-11-07 10:17:03 +0000
received: 10 at: 2019-11-07 10:17:04 +0000
received: 10 at: 2019-11-07 10:17:05 +0000
received: 10 at: 2019-11-07 10:17:06 +0000
received: 10 at: 2019-11-07 10:17:07 +0000
received: 10 at: 2019-11-07 10:17:08 +0000
received: 10 at: 2019-11-07 10:17:09 +0000
received: 10 at: 2019-11-07 10:17:10 +0000
received: 10 at: 2019-11-07 10:17:11 +0000
received: 10 at: 2019-11-07 10:17:12 +0000
received: 10 at: 2019-11-07 10:17:13 +0000
received: 10 at: 2019-11-07 10:17:14 +0000
@jakobmygind jakobmygind changed the title Debounce keeps emitting values even though debounced publisher it's not publishing Debounce keeps emitting values even though debounced publisher is not publishing Nov 7, 2019
@ddddxxx ddddxxx added the bug Something isn't working label Nov 7, 2019
@ddddxxx
Copy link
Member

ddddxxx commented Nov 7, 2019

I find a test case described this behaviour. It seems to be intended, but I can't reproduce this behaviour with Combine. @luoxiu

@ddddxxx
Copy link
Member

ddddxxx commented Nov 7, 2019

Actually the CI is completely broken...

@luoxiu
Copy link
Member

luoxiu commented Nov 7, 2019

According to this test combine has the same behavior.
@jakobmygind Have you tried combine?

@jakobmygind
Copy link
Author

jakobmygind commented Nov 7, 2019

@luoxiu Yes, I am switching back and forth and Native Combine does not do that. That use case where debounce keeps publishing without input seems like a very specific one.

Afaik Debounce does not emit any values if new input was received in the debounce interval and finally publishes 1 event when no new inputs were received and the time expired.

@luoxiu
Copy link
Member

luoxiu commented Nov 7, 2019

@jakobmygind I will investigate this, thanks for the feedback! You are making cx better!

@jakobmygind
Copy link
Author

@luoxiu Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants