@@ -19,7 +19,7 @@ import Swift
19
19
/// create an asynchronous sequence without manually implementing an
20
20
/// asynchronous iterator. In particular, an asynchronous stream is well-suited
21
21
/// to adapt callback- or delegation-based APIs to participate with
22
- /// `async`/ `await`.
22
+ /// `async`- `await`.
23
23
///
24
24
/// You initialize an `AsyncStream` with a closure that receives an
25
25
/// `AsyncStream.Continuation`. Produce elements in this closure, then provide
@@ -34,11 +34,11 @@ import Swift
34
34
/// consumed by a caller iterating over them. Because of this, `AsyncStream`
35
35
/// defines a buffering behavior, allowing the stream to buffer a specific
36
36
/// number of oldest or newest elements. By default, the buffer limit is
37
- /// unbounded, that is, `Int.max`.
37
+ /// `Int.max`, which means the value is unbounded .
38
38
///
39
39
/// ### Adapting Existing Code to Use Streams
40
40
///
41
- /// To adapt existing callback code to use `async` / `await`, use the callbacks
41
+ /// To adapt existing callback code to use `async`- `await`, use the callbacks
42
42
/// to provide values to the stream, by using the continuation's `yield(_:)`
43
43
/// method.
44
44
///
@@ -65,7 +65,7 @@ import Swift
65
65
/// continuation's `yield(_:)` method.
66
66
/// 3. Sets the continuation's `onTermination` property to a closure that
67
67
/// calls `stopMonitoring()` on the monitor.
68
- /// 4. Finally, calls `startMonitoring` on the `QuakeMonitor`.
68
+ /// 4. Calls `startMonitoring` on the `QuakeMonitor`.
69
69
///
70
70
/// extension QuakeMonitor {
71
71
///
@@ -136,16 +136,15 @@ public struct AsyncStream<Element> {
136
136
/// indicates the number of remaining slots in the buffer at the time of
137
137
/// the `yield` call.
138
138
///
139
- /// - Note: From a thread safety viewpoint , `remaining` is a lower bound
139
+ /// - Note: From a thread safety point of view , `remaining` is a lower bound
140
140
/// on the number of remaining slots. This is because a subsequent call
141
141
/// that uses the `remaining` value could race on the consumption of
142
142
/// values from the stream.
143
143
case enqueued( remaining: Int )
144
144
145
145
/// The stream didn't enqueue the element due to a full buffer.
146
146
///
147
- /// The associated element for this case is the element that the stream
148
- /// dropped.
147
+ /// The associated element for this case is the element dropped by the stream.
149
148
case dropped( Element )
150
149
151
150
/// The stream didn't enqueue the element because the stream was in a
@@ -181,7 +180,7 @@ public struct AsyncStream<Element> {
181
180
/// nomally from its suspension point with a given element.
182
181
///
183
182
/// - Parameter value: The value to yield from the continuation.
184
- /// - Returns: A `YieldResult` indicating the success or failure of the
183
+ /// - Returns: A `YieldResult` that indicates the success or failure of the
185
184
/// yield operation.
186
185
///
187
186
/// If nothing is awaiting the next value, this method attempts to buffer the
@@ -197,8 +196,8 @@ public struct AsyncStream<Element> {
197
196
/// Resume the task awaiting the next iteration point by having it return
198
197
/// nil, which signifies the end of the iteration.
199
198
///
200
- /// Calling this function more than once has no effect. Once you call
201
- /// finish, the stream enters a terminal state and produces no further
199
+ /// Calling this function more than once has no effect. After calling
200
+ /// finish, the stream enters a terminal state and doesn't produces any additional
202
201
/// elements.
203
202
public func finish( ) {
204
203
storage. finish ( )
@@ -231,20 +230,20 @@ public struct AsyncStream<Element> {
231
230
/// Constructs an asynchronous stream for an element type, using the
232
231
/// specified buffering policy and element-producing closure.
233
232
///
234
- /// - Parameter elementType: The type of element the `AsyncStream`
235
- /// produces.
236
- /// - Parameter bufferingPolicy: A `Continuation.BufferingPolicy` value to
237
- /// set the stream's buffering behavior. By default, the stream buffers an
238
- /// unlimited number of elements. You can also set the policy to buffer a
239
- /// specified number of oldest or newest elements.
240
- /// - Parameter build: A custom closure that yields values to the
241
- /// `AsyncStream`. This closure receives a `AsyncStream.Continuation`
242
- /// instance that it uses to provide elements to the stream and terminate the
243
- /// stream when finished.
233
+ /// - Parameters:
234
+ /// - elementType: The type of element the `AsyncStream` produces.
235
+ /// - bufferingPolicy: A `Continuation.BufferingPolicy` value to
236
+ /// set the stream's buffering behavior. By default, the stream buffers an
237
+ /// unlimited number of elements. You can also set the policy to buffer a
238
+ /// specified number of oldest or newest elements.
239
+ /// - build: A custom closure that yields values to the
240
+ /// `AsyncStream`. This closure receives a `AsyncStream.Continuation`
241
+ /// instance that it uses to provide elements to the stream and terminate the
242
+ /// stream when finished.
244
243
///
245
244
/// The `AsyncStream.Continuation` received by the `build` closure is
246
- /// appopriate for use in concurrent contexts. It is thread safe to send and
247
- /// finish; all calls are to the continuation are serialized. However, calling
245
+ /// appropriate for use in concurrent contexts. It is thread safe to send and
246
+ /// finish; all calls to the continuation are serialized. However, calling
248
247
/// this from multiple concurrent contexts could result in out-of-order
249
248
/// delivery.
250
249
///
@@ -265,7 +264,7 @@ public struct AsyncStream<Element> {
265
264
/// }
266
265
/// }
267
266
///
268
- /// // call point:
267
+ /// // Call point:
269
268
/// for await random in stream {
270
269
/// print ("\(random)")
271
270
/// }
@@ -291,14 +290,14 @@ public struct AsyncStream<Element> {
291
290
/// Use this convenience initializer when you have an asychronous function
292
291
/// that can produce elements for the stream, and don't want to invoke
293
292
/// a continuation manually. This initializer "unfolds" your closure into
294
- /// a full-blown asynchronous stream. The created stream handles conformance
293
+ /// an asynchronous stream. The created stream handles conformance
295
294
/// to the `AsyncSequence` protocol automatically, including termination
296
295
/// (whether by cancellation or by returning `nil` from the closure to finish
297
296
/// iteration).
298
297
///
299
298
/// The following example shows an `AsyncStream` created with this
300
299
/// initializer that produces random numbers on a one-second interval. This
301
- /// example uses Swift's multiple trailing closure syntax, which omits
300
+ /// example uses the Swift multiple trailing closure syntax, which omits
302
301
/// the `unfolding` parameter label.
303
302
///
304
303
/// let stream = AsyncStream<Int> {
@@ -308,7 +307,7 @@ public struct AsyncStream<Element> {
308
307
/// onCancel: { @Sendable () in print ("Canceled.") }
309
308
/// )
310
309
///
311
- /// // call point:
310
+ /// // Call point:
312
311
/// for await random in stream {
313
312
/// print ("\(random)")
314
313
/// }
@@ -339,10 +338,10 @@ public struct AsyncStream<Element> {
339
338
extension AsyncStream : AsyncSequence {
340
339
/// The asynchronous iterator for iterating an asynchronous stream.
341
340
///
342
- /// This type specifically doesn't conform to `Sendable`. Do not use it from multiple
341
+ /// This type doesn't conform to `Sendable`. Don't use it from multiple
343
342
/// concurrent contexts. It is a programmer error to invoke `next()` from a
344
- /// concurrent context that contends with another such call, and this will
345
- /// result in a call to `fatalError()`.
343
+ /// concurrent context that contends with another such call, which
344
+ /// results in a call to `fatalError()`.
346
345
public struct Iterator : AsyncIteratorProtocol {
347
346
let produce : ( ) async -> Element ?
348
347
@@ -352,12 +351,12 @@ extension AsyncStream: AsyncSequence {
352
351
/// `AsyncStream`.
353
352
///
354
353
/// It is a programmer error to invoke `next()` from a
355
- /// concurrent context that contends with another such call, and this will
356
- /// result in a call to `fatalError()`.
354
+ /// concurrent context that contends with another such call, which
355
+ /// results in a call to `fatalError()`.
357
356
///
358
357
/// If you cancel the task this iterator is running in while `next()` is
359
358
/// awaiting a value, the `AsyncStream` terminates. In this case, `next()`
360
- /// might return `nil` immediately, or might return `nil` on subsequent calls.
359
+ /// might return `nil` immediately, or return `nil` on subsequent calls.
361
360
public mutating func next( ) async -> Element ? {
362
361
await produce ( )
363
362
}
@@ -373,10 +372,10 @@ extension AsyncStream: AsyncSequence {
373
372
@available ( SwiftStdlib 5 . 5 , * )
374
373
extension AsyncStream . Continuation {
375
374
/// Resume the task awaiting the next iteration point by having it return
376
- /// nomally from its suspension point with a given result's success value.
375
+ /// normally from its suspension point with a given result's success value.
377
376
///
378
377
/// - Parameter result: A result to yield from the continuation.
379
- /// - Returns: A `YieldResult` indicating the success or failure of the
378
+ /// - Returns: A `YieldResult` that indicates the success or failure of the
380
379
/// yield operation.
381
380
///
382
381
/// If nothing is awaiting the next value, the method attempts to buffer the
@@ -395,13 +394,13 @@ extension AsyncStream.Continuation {
395
394
}
396
395
397
396
/// Resume the task awaiting the next iteration point by having it return
398
- /// nomally from its suspension point.
397
+ /// normally from its suspension point.
399
398
///
400
- /// - Returns: A `YieldResult` indicating the success or failure of the
399
+ /// - Returns: A `YieldResult` that indicates the success or failure of the
401
400
/// yield operation.
402
401
///
403
402
/// Use this method with `AsyncStream` instances whose `Element` type is
404
- /// `Void`. In this case, the `yield()` call simply unblocks the awaiting
403
+ /// `Void`. In this case, the `yield()` call unblocks the awaiting
405
404
/// iteration; there is no value to return.
406
405
///
407
406
/// If you call this method repeatedly, each call returns immediately, without
0 commit comments