CombineLatestAsyncSequence
public struct CombineLatestAsyncSequence<P, Q> : AsyncSequence where P : AsyncSequence, Q : AsyncSequence
extension CombineLatestAsyncSequence: AsyncIteratorProtocol
An asynchronous sequence that combines two async sequences.
The combined sequence emits a tuple of the most-recent elements from each sequence when any of them emit a value.
If one sequence never emits a value this sequence will finish.
let streamA = .init { continuation in
continuation.yield(1)
continuation.yield(2)
continuation.yield(3)
continuation.yield(4)
continuation.finish()
}
let streamB = .init { continuation in
continuation.yield(5)
continuation.yield(6)
continuation.yield(7)
continuation.yield(8)
continuation.yield(9)
continuation.finish()
}
for await value in streamA.combineLatest(streamB) {
print(value)
}
// Prints:
// (1, 5)
// (2, 6)
// (3, 7)
// (4, 8)
// (4, 9)
-
The kind of elements streamed.
Declaration
Swift
public typealias Element = (P.Element, Q.Element)
-
Creates an async sequence that only emits elements that don’t match the previous element, as evaluated by a provided closure.
Declaration
Swift
public init( _ p: P, _ q: Q )
Parameters
p
An async sequence.
q
An async sequence.
-
next()
AsynchronousProduces 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 returnsnil
.Declaration
Swift
public mutating func next() async rethrows -> Element?
Return Value
The next element or
nil
if the end of the sequence is reached. -
Creates an async iterator that emits elements of this async sequence.
Declaration
Swift
public func makeAsyncIterator() -> CombineLatestAsyncSequence<P, Q>
Return Value
An instance that conforms to
AsyncIteratorProtocol
.