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 delay more than design #8

Open
dourgulf opened this issue Apr 28, 2024 · 0 comments
Open

debounce delay more than design #8

dourgulf opened this issue Apr 28, 2024 · 0 comments

Comments

@dourgulf
Copy link

testcase:
func testDebounce() {
let exp = self.expectation(description: "Task")
Task {
var runCount = 0
for i in 0..<10 {
debounce(option: .runFirst) {
print(Date().printFormat(), "debounce test: (i)")
runCount += 1
}
try? await Task.sleep(for: .milliseconds(600))
}
// exp.fulfill()
}
self.wait(for: [exp], timeout: 10)
}
result:
2024-04-28 09:49:41.257 debounce test: 0
2024-04-28 09:49:41.879 debounce test: 1
2024-04-28 09:49:42.289 debounce test: 0
2024-04-28 01:49:42 +0000 task is cancelled
2024-04-28 01:49:43 +0000 task is cancelled
2024-04-28 01:49:43 +0000 task is cancelled
2024-04-28 01:49:44 +0000 task is cancelled
2024-04-28 01:49:44 +0000 task is cancelled
2024-04-28 01:49:45 +0000 task is cancelled
2024-04-28 01:49:46 +0000 task is cancelled
2024-04-28 01:49:46 +0000 task is cancelled
2024-04-28 09:49:47.855 debounce test: 9

two problem:

  1. first task run two times
  2. task delay more than 1 second(duration)

the debounce expect in duration only trigger only once, but now, it delay much more time than duration

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