I made a post about this here.
I was recently testing out the debounce method and I noticed some strange behavior that I didn't expect. It looks the async stream I have set up is getting cancelled early when I'm calling the debounce method but it doesn't do that without the debounce method. This seems like a bug but I'm curious to hear others thoughts on it.
Here is the reproducer I have. Thanks!
@Test
func debounceCancellation() async {
enum Status {
case inProgress
case completed
}
let drawStatues = AsyncStream<Status> { continuation in
Task {
continuation.yield(.inProgress)
try! await Task.sleep(for: .seconds(2))
continuation.yield(.completed)
}
continuation.onTermination = { termination in
switch termination {
case .cancelled:
print("Cancelled!")
case .finished:
print("Finished!")
@unknown default:
fatalError("Unknown case")
}
}
}
_ = await drawStatues
.debounce(for: .seconds(2))
.first(where: { @Sendable in $0 == .completed })
// Current behavior when using debounce:
// cancelled -> end
//
// Expected behavior without using debounce:
// end -> cancelled
print("End")
}
I made a post about this here.
I was recently testing out the debounce method and I noticed some strange behavior that I didn't expect. It looks the async stream I have set up is getting cancelled early when I'm calling the debounce method but it doesn't do that without the debounce method. This seems like a bug but I'm curious to hear others thoughts on it.
Here is the reproducer I have. Thanks!