Here's a seemingly simple question I can't find an answer to: short of making an ad-hoc implementation of AsyncSequence and AsyncIteratorProtocol, how do I get an async sequence that supports typed throws? AsyncThrowingStream can only be created where Failure == any Error from what I can find, which kind of defeats the purpose of making it generic in the first place.
Yep, the stdlib adoption of typed throws is lagging here.
You can easily enough make
struct AsyncTypedThrowsAdapterSequence<Element, Failure: Error>: AsyncSequence { ... }
extension AsyncSequence where Failure == any Error {
func assertOnlyThrows<E: Error>(
_ errorType: E.Type
) -> AsyncTypedThrowsAdapterSequence<Element, E> { ... }
}
// ...
AsyncThrowingStream(...).assertOnlyThrows(MyErrorType.self)