Skip to content

debounce delay more than design #8

Description

@dourgulf

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions