Closed
Description
I discovered while debugging an issue in my app that the async sequence returned by AsyncThrowingStream.debounce()
silently swallows thrown exceptions, and does not terminate, instead just stalling iteration.
struct MyError: Error {}
let (stream, continuation) = AsyncThrowingStream.makeStream(of: Int.self)
// consume the stream
Task {
do {
for try await value in stream.debounce(for: .seconds(0.1)) {
print(value)
}
print("Stream ended normally")
}
catch {
print("Stream ended by throwing")
}
}
// produce the values (and exception)
Task {
for i in 1...10 {
if i == 5 {
continuation.finish(throwing: MyError())
}
else {
continuation.yield(i)
}
try await Task.sleep(for: .seconds(0.3))
}
continuation.finish()
}
Running this in a playground (see attached project below), the iteration prints 1, 2, 3, 4 and then just stalls.
Removing the debounce
, iteration ends by throwing as expected.
Metadata
Metadata
Assignees
Labels
No labels