Open
Description
Description
issues:
- AsyncStream supports multiple concurrent consumption, but its documentation states that it does not
- AsyncThrowingStream does not support multiple concurrent consumption (its documentation is accurate)
Reproduction
// non-throwing stream
func test_stream() async {
let (s, c) = AsyncStream<Int>.makeStream()
let t1 = Task { @MainActor in
for await _ in s {}
}
await MainActor.run {}
print("installed consumer 1")
let t2 = Task { @MainActor in
for await _ in s {}
}
await MainActor.run {}
print("installed consumer 2")
// works
}
// throwing stream
func test_throwing_stream() async {
let (s, c) = AsyncThrowingStream<Int, Error>.makeStream()
let t1 = Task { @MainActor in
for try await _ in s {}
}
await MainActor.run {}
print("installed consumer 1")
let t2 = Task { @MainActor in
for try await _ in s {}
}
await MainActor.run {}
print("installed consumer 2")
// fatal error shortly after this point
}
Task { await test_stream() }
Task { await test_throwing_stream() }
Expected behavior
the async stream implementations should function analogously with respect to multi-consumption, and the corresponding documentation should accurately reflect their behaviors. in particular, the throwing variant should behave in the same manner that the non-throwing stream does.
Environment
Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0
Additional information
relevant forum posts: