AsyncThrowingStream Failure generic parameter is not customisable

AsyncThrowingStream's initialiser doesn't allow any other error type except Error:
If you try other type you will get compilation error:

Initializer 'init(:bufferingPolicy::)' requires the types 'CancellationError' and 'Error' be equivalent

It's because all initializers have restriction: where Failure == Error

So Failure isn't customisable and should be removed for this reason

Interestingly enough, the Failure generic was not in the original proposal. I believe it was added later with the assumption that Swift will introduce "typed" throws in the future.

1 Like
Terms of Service

Privacy Policy

Cookie Policy