Skip to content

Commit db293ae

Browse files
author
Chris Adamson
committed
Source docs for AsyncThrowingStream.
1 parent 91537c0 commit db293ae

File tree

2 files changed

+314
-77
lines changed

2 files changed

+314
-77
lines changed

stdlib/public/Concurrency/AsyncStream.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public struct AsyncStream<Element> {
149149

150150
/// A strategy that handles exhaustion of a buffer’s capacity.
151151
public enum BufferingPolicy {
152+
/// Continue to add to the buffer, treating its capacity as infinite.
152153
case unbounded
153154

154155
/// When the buffer is full, discard the newly received element.
@@ -191,14 +192,15 @@ public struct AsyncStream<Element> {
191192
storage.finish()
192193
}
193194

194-
/// A callback to invoke when canceling iteration of a AsyncStream.
195+
/// A callback to invoke when canceling iteration of an asynchronous
196+
/// stream.
195197
///
196-
/// If an `onTermination` callback is set, using task cancelation to
197-
/// terminate iteration of a AsyncStream results in a call to this
198+
/// If an `onTermination` callback is set, using task cancellation to
199+
/// terminate iteration of a `AsyncStream` results in a call to this
198200
/// callback.
199201
///
200202
/// Cancelling an active iteration invokes the `onTermination` callback
201-
/// first, then resumes by yeilding `nil`. This means that you can perform
203+
/// first, then resumes by yielding `nil`. This means that you can perform
202204
/// needed cleanup in the cancellation handler. After reaching a terminal
203205
/// state, the `AsyncStream` disposes of the callback.
204206
public var onTermination: (@Sendable (Termination) -> Void)? {
@@ -223,9 +225,9 @@ public struct AsyncStream<Element> {
223225
/// `Continuation.BufferingPolicy` to buffer a specified number of oldest
224226
/// or newest elements.
225227
/// - Parameter build: A custom closure that yields values to the
226-
/// `AsyncStream`. This closure receives a `AsyncStream.Continuation` object
227-
/// that it uses to provide elements to the stream and terminate the stream
228-
/// when finished.
228+
/// `AsyncStream`. This closure receives a `AsyncStream.Continuation`
229+
/// instance that it uses to provide elements to the stream and terminate the
230+
/// stream when finished.
229231
///
230232
/// The `AsyncStream.Contuation` received by the `build` closure is appopriate
231233
/// for use in concurrent contexts. It is thread safe to send and finish; all
@@ -235,7 +237,7 @@ public struct AsyncStream<Element> {
235237
/// The following example shows an `AsyncStream` created with this
236238
/// initializer that produces random numbers on a one-second interval. When
237239
/// a private `keepRunning` variable becomes `false`, the inner `while` loop
238-
///
240+
/// exits and the stream finishes.
239241
///
240242
/// let stream = AsyncStream<Int>(
241243
/// Int.self, bufferingPolicy: .bufferingNewest(5)) { continuation in
@@ -345,7 +347,8 @@ extension AsyncStream: AsyncSequence {
345347
}
346348
}
347349

348-
/// Constructs an iterator.
350+
/// Creates the asynchronous iterator that produces elements of this
351+
/// asynchronous sequence.
349352
public func makeAsyncIterator() -> Iterator {
350353
return Iterator(produce: produce)
351354
}
@@ -381,7 +384,7 @@ extension AsyncStream.Continuation {
381384
/// - Returns: A `YieldResult` indicating the success or failure of the
382385
/// yield operation.
383386
///
384-
/// Use this method with `AsyncStream` instances whose element type is
387+
/// Use this method with `AsyncStream` instances whose `Element` type is
385388
/// `Void`. In this case, the `yield()` call simply unblocks the awaiting
386389
/// iteration; there is no value to return.
387390
///

0 commit comments

Comments
 (0)