Skip to content

Commit e514c65

Browse files
committed
UncheckedSendable: AsyncSequence
Currently, a non-sendable sequence cannot be erased to `AsyncStream` using this library's initializers even if one takes care to traffic it through via `nonisolated(unsafe)`: ```swift nonisolated(unsafe) let nonSendable = nonSendable AsyncStream(nonSendable) // 🛑 ``` This conditional conformance acts as a workaround: ```swift AsyncStream(UncheckedSendable(nonSendable)) ``` Ideally folks can stop using our concrete async sequence eraser in favor of `any AsyncSequence<Element, Failure>`, but this requires a minimum deployment target of iOS 18, so it won't be an option for many people for some time.
1 parent dccc3fa commit e514c65

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Sources/ConcurrencyExtras/UncheckedSendable.swift

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ public struct UncheckedSendable<Value>: @unchecked Sendable {
5555
}
5656
}
5757

58+
extension UncheckedSendable: AsyncSequence where Value: AsyncSequence {
59+
public func makeAsyncIterator() -> Value.AsyncIterator {
60+
value.makeAsyncIterator()
61+
}
62+
}
63+
5864
#if swift(>=5.10)
5965
@available(iOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead.")@available(
6066
macOS, deprecated: 9999, message: "Use 'nonisolated(unsafe) let', instead."

0 commit comments

Comments
 (0)