PassthroughAsyncSequence
public struct PassthroughAsyncSequence<Element> : AsyncSequence
A async sequence that broadcasts elements.
let sequence = PassthroughAsyncSequence<Int>()
sequence.yield(0)
sequence.yield(1)
sequence.yield(2)
sequence.finish()
for await value in sequence {
print(value)
}
// Prints:
// 0
// 1
// 2
-
Creates an async sequence that broadcasts elements.
Declaration
Swift
public init()
-
Creates an async iterator that emits elements of this async sequence.
Declaration
Swift
public func makeAsyncIterator() -> AsyncStream<Element>.Iterator
Return Value
An instance that conforms to
AsyncIteratorProtocol
.
-
Yield a new element to the sequence.
Yielding a new element will emit it through the sequence.
Declaration
Swift
public func yield(_ element: Element)
Parameters
element
The element to yield.
-
Mark the sequence as finished by having it’s iterator emit nil.
Once finished, any calls to yield will result in no change.
Declaration
Swift
public func finish()
-
Emit one last element beford marking the sequence as finished by having it’s iterator emit nil.
Once finished, any calls to yield will result in no change.
Declaration
Swift
public func finish(with element: Element)
Parameters
element
The element to emit.