Please try the following solution:
macOS 15's AsyncSequence
defines a Failure
type, which is not available in earlier versions.
Therefore, we utilize the associatedtype
keyword and create a new protocol FailureableAsyncSequence
that associates a new Failure
type. We make AsyncStream
conform to both protocols.
When the AsyncSequence
in older systems does not define Failure
, it will automatically associate with the Failure
type from our new protocol.
Although this does not perfectly solve your problem, it is a feasible solution.
public protocol SomeAsyncSequence: AsyncSequence {
}
public protocol FailureableAsyncSequence {
associatedtype Failure: Error
}
public typealias CustomAsyncSequence = SomeAsyncSequence & FailureableAsyncSequence
extension AsyncStream: CustomAsyncSequence where Element == Int {
public typealias Failure = Never
}
public final class EmitterOfEvents {
public typealias Element = Int
public func notifications() -> some CustomAsyncSequence {
AsyncStream<Element>.makeStream().stream
}
}