AsyncStream
extension AsyncStream
-
Construct a AsyncStream buffering given an Element type.
The maximum number of pending elements limited by dropping the oldest value when a new value comes in if the buffer would excede the limit placed upon it. By default this limit is unlimited.
The build closure passes in a Continuation which can be used in concurrent contexts. It is thread safe to send and finish; all calls are to the continuation are serialized, however calling this from multiple concurrent contexts could result in out of order delivery.
Declaration
Swift
public init( _ elementType: Element.Type = Element.self, bufferingPolicy limit: AsyncStream<Element>.Continuation.BufferingPolicy = .unbounded, _ build: @escaping (AsyncStream<Element>.Continuation) async -> Void )
Parameters
elementType
The type the AsyncStream will produce.
maxBufferedElements
The maximum number of elements to hold in the buffer past any checks for continuations being resumed.
build
The work associated with yielding values to the AsyncStream.
-
Declaration
Swift
extension AsyncStream.Continuation