@@ -129,12 +129,14 @@ public struct AsyncStream<Element> {
129
129
///
130
130
/// This value reprsents the successful enqueueing of an element, whether
131
131
/// the stream buffers the element or delivers it immediately to a pending
132
- /// call to `next()`. The associated value `remaining` indicates the
133
- /// number of remaining slots in the buffer at the point in time of
134
- /// yielding .
132
+ /// call to `next()`. The associated value `remaining` is a hint that
133
+ /// indicates the number of remaining slots in the buffer at the time of
134
+ /// the `yield` call .
135
135
///
136
- /// > Note: Acting on the remaining count is valid only when calls to
137
- /// yield are mutually exclusive.
136
+ /// > Note: From a thread safety viewpoint, `remaining` is a lower bound
137
+ /// on the number of remaining slots. This is because a subsequent call
138
+ /// that uses the `remaining` value could race on the consumption of
139
+ /// values from the stream.
138
140
case enqueued( remaining: Int )
139
141
140
142
/// The stream didn't enqueue the element due to a full buffer.
@@ -153,17 +155,20 @@ public struct AsyncStream<Element> {
153
155
154
156
/// A strategy that handles exhaustion of a buffer’s capacity.
155
157
public enum BufferingPolicy {
156
- /// Continue to add to the buffer, treating its capacity as infinite.
158
+ /// Continue to add to the buffer, without imposing a limit on the number
159
+ /// of buffered elements.
157
160
case unbounded
158
161
159
162
/// When the buffer is full, discard the newly received element.
160
163
///
161
- /// This strategy enforces keeping the specified number of oldest values.
164
+ /// This strategy enforces keeping at most the specified number of oldest
165
+ /// values.
162
166
case bufferingOldest( Int )
163
167
164
168
/// When the buffer is full, discard the oldest element in the buffer.
165
169
///
166
- /// This strategy enforces keeping the specified number of newest values.
170
+ /// This strategy enforces keeping at most the specified number of newest
171
+ /// values.
167
172
case bufferingNewest( Int )
168
173
}
169
174
@@ -180,7 +185,7 @@ public struct AsyncStream<Element> {
180
185
/// result's element.
181
186
///
182
187
/// This can be called more than once and returns to the caller immediately
183
- /// without blocking for any awaiting consuption from the iteration.
188
+ /// without blocking for any awaiting consumption from the iteration.
184
189
@discardableResult
185
190
public func yield( _ value: __owned Element) -> YieldResult {
186
191
storage. yield ( value)
@@ -206,7 +211,8 @@ public struct AsyncStream<Element> {
206
211
/// Canceling an active iteration invokes the `onTermination` callback
207
212
/// first, then resumes by yielding `nil`. This means that you can perform
208
213
/// needed cleanup in the cancellation handler. After reaching a terminal
209
- /// state, the `AsyncStream` disposes of the callback.
214
+ /// state as a result of cancellation, the `AsyncStream` sets the callback
215
+ /// to `nil`.
210
216
public var onTermination : ( @Sendable ( Termination ) -> Void ) ? {
211
217
get {
212
218
return storage. getOnTermination ( )
@@ -224,10 +230,10 @@ public struct AsyncStream<Element> {
224
230
///
225
231
/// - Parameter elementType: The type of element the `AsyncStream`
226
232
/// produces.
227
- /// - Parameter limit: The maximum number of elements to hold in the buffer.
228
- /// By default, this value is unlimited. Use a
229
- /// `Continuation.BufferingPolicy` to buffer a specified number of oldest
230
- /// or newest elements.
233
+ /// - Parameter bufferingPolicy: A `Continuation.BufferingPolicy` value to
234
+ /// set the stream's buffering behavior. By default, the stream buffers an
235
+ /// unlimited number of elements. You can also set the policy to buffer a
236
+ /// specified number of oldest or newest elements.
231
237
/// - Parameter build: A custom closure that yields values to the
232
238
/// `AsyncStream`. This closure receives a `AsyncStream.Continuation`
233
239
/// instance that it uses to provide elements to the stream and terminate the
@@ -280,9 +286,9 @@ public struct AsyncStream<Element> {
280
286
/// Use this convenience initializer when you have an asychronous function
281
287
/// that can produce elements for the stream, and don't want to invoke
282
288
/// a continuation manually. This initializer "unfolds" your closure into
283
- /// a full-blown asynchronous stream. The created stream handles adherence to
284
- /// the `AsyncSequence` protocol automatically, including termination (whether
285
- /// by cancellation or by returning `nil` from the closure to finish
289
+ /// a full-blown asynchronous stream. The created stream handles conformance
290
+ /// to the `AsyncSequence` protocol automatically, including termination
291
+ /// (whether by cancellation or by returning `nil` from the closure to finish
286
292
/// iteration).
287
293
///
288
294
/// The following example shows an `AsyncStream` created with this
0 commit comments