Merge3AsyncSequence

public struct Merge3AsyncSequence<T> : AsyncSequence where T : AsyncSequence
extension Merge3AsyncSequence: AsyncIteratorProtocol

An asynchronous sequence that merges three async sequences.

The sequences are iterated through in parallel.

let streamA = .init { continuation in
    continuation.yield(1)
    continuation.yield(4)
    continuation.finish()
}

let streamB = .init { continuation in
    continuation.yield(2)
    continuation.finish()
}

let streamC = .init { continuation in
    continuation.yield(3)
    continuation.finish()
}

for await value in self.streamA.merge(with: self.streamB, self.streamC) {
    print(value)
}

// Prints:
// 1
// 2
// 3
// 4
  • The kind of elements streamed.

    Declaration

    Swift

    public typealias Element = T.Element

Initialization

  • Creates an async sequence that merges the provided async sequence’s.

    Declaration

    Swift

    public init(
        _ p: T,
        _ q: T,
        _ r: T
    )

    Parameters

    p

    An async sequence.

    q

    An async sequence.

AsyncSequence

  • Creates an async iterator that emits elements of this async sequence.

    Declaration

    Swift

    public func makeAsyncIterator() -> AsyncThrowingStream<Element, Error>.Iterator

    Return Value

    An instance that conforms to AsyncIteratorProtocol.

AsyncIteratorProtocol

  • next() Asynchronous

    Produces the next element in the sequence.

    Continues to call next() on it’s base iterator and iterator of it’s combined sequence.

    If both iterator’s return nil, indicating the end of the sequence, this iterator returns nil.

    Declaration

    Swift

    public mutating func next() async rethrows -> Element?

    Return Value

    The next element or nil if the end of the sequence is reached.