Skip to content

Commit c11034c

Browse files
Apply Chuck's suggestions from code review
Co-authored-by: Chuck Toporek <[email protected]>
1 parent 6b62146 commit c11034c

File tree

2 files changed

+65
-66
lines changed

2 files changed

+65
-66
lines changed

stdlib/public/Concurrency/AsyncStream.swift

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Swift
1919
/// create an asynchronous sequence without manually implementing an
2020
/// asynchronous iterator. In particular, an asynchronous stream is well-suited
2121
/// to adapt callback- or delegation-based APIs to participate with
22-
/// `async`/`await`.
22+
/// `async`-`await`.
2323
///
2424
/// You initialize an `AsyncStream` with a closure that receives an
2525
/// `AsyncStream.Continuation`. Produce elements in this closure, then provide
@@ -34,11 +34,11 @@ import Swift
3434
/// consumed by a caller iterating over them. Because of this, `AsyncStream`
3535
/// defines a buffering behavior, allowing the stream to buffer a specific
3636
/// 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.
3838
///
3939
/// ### Adapting Existing Code to Use Streams
4040
///
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
4242
/// to provide values to the stream, by using the continuation's `yield(_:)`
4343
/// method.
4444
///
@@ -65,7 +65,7 @@ import Swift
6565
/// continuation's `yield(_:)` method.
6666
/// 3. Sets the continuation's `onTermination` property to a closure that
6767
/// calls `stopMonitoring()` on the monitor.
68-
/// 4. Finally, calls `startMonitoring` on the `QuakeMonitor`.
68+
/// 4. Calls `startMonitoring` on the `QuakeMonitor`.
6969
///
7070
/// extension QuakeMonitor {
7171
///
@@ -136,16 +136,15 @@ public struct AsyncStream<Element> {
136136
/// indicates the number of remaining slots in the buffer at the time of
137137
/// the `yield` call.
138138
///
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
140140
/// on the number of remaining slots. This is because a subsequent call
141141
/// that uses the `remaining` value could race on the consumption of
142142
/// values from the stream.
143143
case enqueued(remaining: Int)
144144

145145
/// The stream didn't enqueue the element due to a full buffer.
146146
///
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.
149148
case dropped(Element)
150149

151150
/// The stream didn't enqueue the element because the stream was in a
@@ -181,7 +180,7 @@ public struct AsyncStream<Element> {
181180
/// nomally from its suspension point with a given element.
182181
///
183182
/// - 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
185184
/// yield operation.
186185
///
187186
/// If nothing is awaiting the next value, this method attempts to buffer the
@@ -197,8 +196,8 @@ public struct AsyncStream<Element> {
197196
/// Resume the task awaiting the next iteration point by having it return
198197
/// nil, which signifies the end of the iteration.
199198
///
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
202201
/// elements.
203202
public func finish() {
204203
storage.finish()
@@ -231,20 +230,20 @@ public struct AsyncStream<Element> {
231230
/// Constructs an asynchronous stream for an element type, using the
232231
/// specified buffering policy and element-producing closure.
233232
///
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.
244243
///
245244
/// 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
248247
/// this from multiple concurrent contexts could result in out-of-order
249248
/// delivery.
250249
///
@@ -265,7 +264,7 @@ public struct AsyncStream<Element> {
265264
/// }
266265
/// }
267266
///
268-
/// // call point:
267+
/// // Call point:
269268
/// for await random in stream {
270269
/// print ("\(random)")
271270
/// }
@@ -291,14 +290,14 @@ public struct AsyncStream<Element> {
291290
/// Use this convenience initializer when you have an asychronous function
292291
/// that can produce elements for the stream, and don't want to invoke
293292
/// 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
295294
/// to the `AsyncSequence` protocol automatically, including termination
296295
/// (whether by cancellation or by returning `nil` from the closure to finish
297296
/// iteration).
298297
///
299298
/// The following example shows an `AsyncStream` created with this
300299
/// 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
302301
/// the `unfolding` parameter label.
303302
///
304303
/// let stream = AsyncStream<Int> {
@@ -308,7 +307,7 @@ public struct AsyncStream<Element> {
308307
/// onCancel: { @Sendable () in print ("Canceled.") }
309308
/// )
310309
///
311-
/// // call point:
310+
/// // Call point:
312311
/// for await random in stream {
313312
/// print ("\(random)")
314313
/// }
@@ -339,10 +338,10 @@ public struct AsyncStream<Element> {
339338
extension AsyncStream: AsyncSequence {
340339
/// The asynchronous iterator for iterating an asynchronous stream.
341340
///
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
343342
/// 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()`.
346345
public struct Iterator: AsyncIteratorProtocol {
347346
let produce: () async -> Element?
348347

@@ -352,12 +351,12 @@ extension AsyncStream: AsyncSequence {
352351
/// `AsyncStream`.
353352
///
354353
/// 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()`.
357356
///
358357
/// If you cancel the task this iterator is running in while `next()` is
359358
/// 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.
361360
public mutating func next() async -> Element? {
362361
await produce()
363362
}
@@ -373,10 +372,10 @@ extension AsyncStream: AsyncSequence {
373372
@available(SwiftStdlib 5.5, *)
374373
extension AsyncStream.Continuation {
375374
/// 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.
377376
///
378377
/// - 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
380379
/// yield operation.
381380
///
382381
/// If nothing is awaiting the next value, the method attempts to buffer the
@@ -395,13 +394,13 @@ extension AsyncStream.Continuation {
395394
}
396395

397396
/// Resume the task awaiting the next iteration point by having it return
398-
/// nomally from its suspension point.
397+
/// normally from its suspension point.
399398
///
400-
/// - Returns: A `YieldResult` indicating the success or failure of the
399+
/// - Returns: A `YieldResult` that indicates the success or failure of the
401400
/// yield operation.
402401
///
403402
/// 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
405404
/// iteration; there is no value to return.
406405
///
407406
/// If you call this method repeatedly, each call returns immediately, without

stdlib/public/Concurrency/AsyncThrowingStream.swift

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Swift
1919
/// way to create an asynchronous sequence without manually implementing an
2020
/// asynchronous iterator. In particular, an asynchronous stream is well-suited
2121
/// to adapt callback- or delegation-based APIs to participate with
22-
/// `async`/`await`.
22+
/// `async`-`await`.
2323
///
2424
/// In contrast to `AsyncStream`, this type can throw an error from the awaited
2525
/// `next()`, which terminates the stream with the thrown error.
@@ -39,11 +39,11 @@ import Swift
3939
/// consumed by a caller iterating over them. Because of this, `AsyncThrowingStream`
4040
/// defines a buffering behavior, allowing the stream to buffer a specific
4141
/// number of oldest or newest elements. By default, the buffer limit is
42-
/// unbounded, that is, `Int.max`.
42+
/// `Int.max`, which means it's unbounded.
4343
///
4444
/// ### Adapting Existing Code to Use Streams
4545
///
46-
/// To adapt existing callback code to use `async` / `await`, use the callbacks
46+
/// To adapt existing callback code to use `async`-`await`, use the callbacks
4747
/// to provide values to the stream, by using the continuation's `yield(_:)`
4848
/// method.
4949
///
@@ -74,10 +74,10 @@ import Swift
7474
/// 3. Sets the monitor's `errorHandler` property to a closure that receives
7575
/// any error from the monitor and forwards it to the stream by calling the
7676
/// continuation's `finish(throwing:)` method. This causes the stream's
77-
/// iterator to throw the error, terminating the stream.
77+
/// iterator to throw the error and terminate the stream.
7878
/// 4. Sets the continuation's `onTermination` property to a closure that
7979
/// calls `stopMonitoring()` on the monitor.
80-
/// 5. Finally, calls `startMonitoring` on the `QuakeMonitor`.
80+
/// 5. Calls `startMonitoring` on the `QuakeMonitor`.
8181
///
8282
/// extension QuakeMonitor {
8383
///
@@ -99,9 +99,8 @@ import Swift
9999
/// }
100100
///
101101
///
102-
/// Since the stream is an `AsyncSequence`, the call point can use the
103-
/// `for`-`await`-`in` syntax to process each `Quake` instance as the stream
104-
/// produces it:
102+
/// Because the stream is an `AsyncSequence`, the call point uses the
103+
/// `for`-`await`-`in` syntax to process each `Quake` instance as produced by the stream:
105104
///
106105
/// do {
107106
/// for try await quake in quakeStream {
@@ -177,7 +176,7 @@ public struct AsyncThrowingStream<Element, Failure: Error> {
177176
///
178177
/// This indicates the stream terminated prior to calling `yield`, either
179178
/// because the stream finished normally or through cancellation, or
180-
/// threw an error
179+
/// threw an error.
181180
case terminated
182181
}
183182

@@ -204,7 +203,7 @@ public struct AsyncThrowingStream<Element, Failure: Error> {
204203
/// nomally from its suspension point with a given element.
205204
///
206205
/// - Parameter value: The value to yield from the continuation.
207-
/// - Returns: A `YieldResult` indicating the success or failure of the
206+
/// - Returns: A `YieldResult` that indicates the success or failure of the
208207
/// yield operation.
209208
///
210209
/// If nothing is awaiting the next value, the method attempts to buffer the
@@ -220,10 +219,10 @@ public struct AsyncThrowingStream<Element, Failure: Error> {
220219
/// Resume the task awaiting the next iteration point by having it return
221220
/// nil, which signifies the end of the iteration.
222221
///
223-
/// - Parameter error: The error to throw, or `nil` to finish normally.
222+
/// - Parameter error: The error to throw, or `nil`, to finish normally.
224223
///
225-
/// Calling this function more than once has no effect. Once you call
226-
/// finish, the stream enters a terminal state and produces no further
224+
/// Calling this function more than once has no effect. After calling
225+
/// finish, the stream enters a terminal state and doesn't produce any additional
227226
/// elements.
228227
public func finish(throwing error: __owned Failure? = nil) {
229228
storage.finish(throwing: error)
@@ -236,11 +235,11 @@ public struct AsyncThrowingStream<Element, Failure: Error> {
236235
/// terminate iteration of a `AsyncThrowingStream` results in a call to this
237236
/// callback.
238237
///
239-
/// Cancelling an active iteration invokes the `onTermination` callback
240-
/// first, then resumes by yielding `nil` or throwing an error from the
238+
/// Canceling an active iteration invokes the `onTermination` callback
239+
/// first, and then resumes by yielding `nil` or throwing an error from the
241240
/// iterator. This means that you can perform needed cleanup in the
242241
/// cancellation handler. After reaching a terminal state, the
243-
/// `AsyncThrowingStream` disposes of the callback.
242+
/// `AsyncThrowingStream` disposes of the callback.
244243
public var onTermination: (@Sendable (Termination) -> Void)? {
245244
get {
246245
return storage.getOnTermination()
@@ -256,13 +255,14 @@ public struct AsyncThrowingStream<Element, Failure: Error> {
256255
/// Constructs an asynchronous stream for an element type, using the
257256
/// specified buffering policy and element-producing closure.
258257
///
259-
/// - Parameter elementType: The type of element the `AsyncThrowingStream`
260-
/// produces
261-
/// - Parameter limit: The maximum number of elements to
258+
/// - Parameters:
259+
/// - elementType: The type of element the `AsyncThrowingStream`
260+
/// produces.
261+
/// - limit: The maximum number of elements to
262262
/// hold in the buffer. By default, this value is unlimited. Use a
263263
/// `Continuation.BufferingPolicy` to buffer a specified number of oldest
264264
/// or newest elements.
265-
/// - Parameter build: A custom closure that yields values to the
265+
/// - build: A custom closure that yields values to the
266266
/// `AsyncThrowingStream`. This closure receives an
267267
/// `AsyncThrowingStream.Continuation` instance that it uses to provide
268268
/// elements to the stream and terminate the stream when finished.
@@ -297,7 +297,7 @@ public struct AsyncThrowingStream<Element, Failure: Error> {
297297
/// }
298298
/// }
299299
///
300-
/// // call point:
300+
/// // Call point:
301301
/// do {
302302
/// for try await random in stream {
303303
/// print ("\(random)")
@@ -344,7 +344,7 @@ public struct AsyncThrowingStream<Element, Failure: Error> {
344344
/// return random
345345
/// }
346346
///
347-
/// // call point:
347+
/// // Call point:
348348
/// do {
349349
/// for try await random in stream {
350350
/// print ("\(random)")
@@ -364,10 +364,10 @@ public struct AsyncThrowingStream<Element, Failure: Error> {
364364
extension AsyncThrowingStream: AsyncSequence {
365365
/// The asynchronous iterator for iterating an asynchronous stream.
366366
///
367-
/// This type is specificially not `Sendable`. Do not use it from multiple
367+
/// This type is not `Sendable`. Don't use it from multiple
368368
/// concurrent contexts. It is a programmer error to invoke `next()` from a
369-
/// concurrent context that contends with another such call, and this will
370-
/// result in a call to `fatalError()`.
369+
/// concurrent context that contends with another such call, which
370+
/// results in a call to `fatalError()`.
371371
public struct Iterator: AsyncIteratorProtocol {
372372
let produce: () async throws -> Element?
373373

@@ -377,7 +377,7 @@ extension AsyncThrowingStream: AsyncSequence {
377377
/// `AsyncThrowingStream`.
378378
///
379379
/// It is a programmer error to invoke `next()` from a concurrent context
380-
/// that contends with another such call, and this will result in a call to
380+
/// that contends with another such call, which results in a call to
381381
/// `fatalError()`.
382382
///
383383
/// If you cancel the task this iterator is running in while `next()` is
@@ -407,7 +407,7 @@ extension AsyncThrowingStream.Continuation {
407407
/// iterator's `next()` method. If the result is the `failure(_:)` case,
408408
/// this call terminates the stream with the result's error, by calling
409409
/// `finish(throwing:)`.
410-
/// - Returns: A `YieldResult` indicating the success or failure of the
410+
/// - Returns: A `YieldResult` that indicates the success or failure of the
411411
/// yield operation.
412412
///
413413
/// If nothing is awaiting the next value and the result is success, this call
@@ -431,11 +431,11 @@ extension AsyncThrowingStream.Continuation {
431431
/// Resume the task awaiting the next iteration point by having it return
432432
/// nomally from its suspension point.
433433
///
434-
/// - Returns: A `YieldResult` indicating the success or failure of the
434+
/// - Returns: A `YieldResult` that indicates the success or failure of the
435435
/// yield operation.
436436
///
437437
/// Use this method with `AsyncThrowingStream` instances whose `Element`
438-
/// type is `Void`. In this case, the `yield()` call simply unblocks the
438+
/// type is `Void`. In this case, the `yield()` call unblocks the
439439
/// awaiting iteration; there is no value to return.
440440
///
441441
/// If you call this method repeatedly, each call returns immediately,

0 commit comments

Comments
 (0)