mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Implement AsyncIteratorProtocol.next() in terms of next(isolation:).
New async iterators should be able to implement only `next(isolation:)` and get the older `next()` implementation via a default. Implement the appropriate default witness. Fixes rdar://125447861.
This commit is contained in:
@@ -111,8 +111,9 @@ public protocol AsyncIteratorProtocol<Element, Failure> {
|
||||
|
||||
@available(SwiftStdlib 5.1, *)
|
||||
extension AsyncIteratorProtocol {
|
||||
/// Default implementation of `next()` in terms of `next()`, which is
|
||||
/// required to maintain backward compatibility with existing async iterators.
|
||||
/// Default implementation of `next(isolation:)` in terms of `next()`, which
|
||||
/// is required to maintain backward compatibility with existing async
|
||||
/// iterators.
|
||||
@available(SwiftStdlib 6.0, *)
|
||||
@inlinable
|
||||
public mutating func next(isolation actor: isolated (any Actor)?) async throws(Failure) -> Element? {
|
||||
@@ -123,3 +124,15 @@ extension AsyncIteratorProtocol {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.1, *)
|
||||
extension AsyncIteratorProtocol {
|
||||
/// Default implementation of `next()` in terms of `next(isolation:)`, which
|
||||
/// is required to maintain backward compatibility with existing async
|
||||
/// iterators.
|
||||
@available(SwiftStdlib 6.0, *)
|
||||
@inlinable
|
||||
public mutating func next() async throws(Failure) -> Element? {
|
||||
return try await next(isolation: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,3 +75,13 @@ enum MyError: Error {
|
||||
func getASequence() -> any AsyncSequence<Data, MyError> {
|
||||
return ErrorSequence<Data, _>(throwError: MyError.foo) // ERROR: Cannot convert return expression of type 'any Error' to return type 'MyError'
|
||||
}
|
||||
|
||||
// Test the default implementation of next() in terms of next(isolation:).
|
||||
struct AsyncIteratorWithOnlyNextIsolation: AsyncIteratorProtocol {
|
||||
public mutating func next(isolation: (any Actor)?) throws(MyError) -> Int? { 0 }
|
||||
}
|
||||
|
||||
// Test the default implementation of next(isolation:) in terms of next().
|
||||
struct AsyncIteratorWithOnlyNext: AsyncIteratorProtocol {
|
||||
public mutating func next() throws(MyError) -> Int? { 0 }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user