Asynchronous streams
Asynchronous streams are similar to asynchronous sequences. AsyncStream
is the Swift protocol that defines asynchronous streams. It is less flexible, simpler to use, and requires less code than AsyncSequence
.
The AsyncStream
protocol conforms to AsyncSequence
, but it offers a more streamlined method for generating asynchronous sequences and does not require you to define manually an asynchronous iterator.
AsyncStream
’s initializer is defined as follows:
init(Element.Type, bufferingPolicy: AsyncStream<Element>.Continuation.BufferingPolicy, (AsyncStream<Element>.Continuation) -> Void)
The initializer builds an asynchronous stream for an element type, with the specified buffering policy and the element-producing closure “continuation.”
Continuations in computer science are abstract representations of the control state of a computer program. A continuation captures the computation that remains to be executed at a certain...