CatchErrorAsyncSequence
public struct CatchErrorAsyncSequence<Base, NewAsyncSequence>: AsyncSequence where
Base: AsyncSequence,
NewAsyncSequence: AsyncSequence,
Base.Element == NewAsyncSequence.Element
extension CatchErrorAsyncSequence: AsyncIteratorProtocol
Catches any errors in the async sequence and replaces it with the provided async sequence.
let sequence = Fail<Int, TestError>(
error: TestError()
)
.catch { error in
Just(-1)
}
for await value in stream {
print(value)
}
// Prints:
// -1
-
The kind of elements streamed.
Declaration
Swift
public typealias Element = Base.Element
-
Creates an async sequence that replaces any errors in the sequence with a provided element.
Declaration
Swift
public init( base: Base, handler: @escaping (Error) -> NewAsyncSequence )
Parameters
base
The async sequence in which this sequence receives it’s elements.
output
The element with which to replace errors from the base async sequence.
-
Creates an async iterator that emits elements of this async sequence.
Declaration
Swift
public func makeAsyncIterator() -> CatchErrorAsyncSequence<Base, NewAsyncSequence>
Return Value
An instance that conforms to
AsyncIteratorProtocol
.