Skip to content

Commit 3ed8f9f

Browse files
author
Chris Adamson
committed
Update code snippet in docs for AsyncStream.init
1 parent 3e3538b commit 3ed8f9f

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

stdlib/public/Concurrency/AsyncStream.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,20 +239,22 @@ public struct AsyncStream<Element> {
239239
/// instance that it uses to provide elements to the stream and terminate the
240240
/// stream when finished.
241241
///
242-
/// The `AsyncStream.Continuation` received by the `build` closure is appopriate
243-
/// for use in concurrent contexts. It is thread safe to send and finish; all
244-
/// calls are to the continuation are serialized, however calling this from
245-
/// multiple concurrent contexts could result in out-of-order delivery.
242+
/// The `AsyncStream.Continuation` received by the `build` closure is
243+
/// appopriate for use in concurrent contexts. It is thread safe to send and
244+
/// finish; all calls are to the continuation are serialized. However, calling
245+
/// this from multiple concurrent contexts could result in out-of-order
246+
/// delivery.
246247
///
247248
/// The following example shows an `AsyncStream` created with this
248-
/// initializer that produces random numbers on a one-second interval. When
249-
/// a private `keepRunning` variable becomes `false`, the inner `while` loop
250-
/// exits and the stream finishes.
249+
/// initializer that produces 100 random numbers on a one-second interval,
250+
/// calling `yield(_:)` to deliver each element to the awaiting call point.
251+
/// When the `for` loop exits and the stream finishes by calling the
252+
/// continuation's `finish()` method.
251253
///
252254
/// let stream = AsyncStream<Int>(Int.self,
253255
/// bufferingPolicy: .bufferingNewest(5)) { continuation in
254256
/// Task.detached {
255-
/// while keepRunning {
257+
/// for _ in 0..<100 {
256258
/// await Task.sleep(1 * 1_000_000_000)
257259
/// continuation.yield(Int.random(in: 1...10))
258260
/// }

stdlib/public/Concurrency/AsyncThrowingStream.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,22 +264,23 @@ public struct AsyncThrowingStream<Element, Failure: Error> {
264264
/// `AsyncThrowingStream.Continuation` instance that it uses to provide
265265
/// elements to the stream and terminate the stream when finished.
266266
///
267-
/// The `AsyncThrowingStream.Continuation` received by the `build` closure is
267+
/// The `AsyncStream.Continuation` received by the `build` closure is
268268
/// appopriate for use in concurrent contexts. It is thread safe to send and
269-
/// finish; all calls are to the continuation are serialized, however calling
270-
/// this from multiple concurrent contexts could result in out of order
271-
/// delivery.
269+
/// finish; all calls are to the continuation are serialized. However, calling
270+
/// this from multiple concurrent contexts could result in out-of-order
271+
/// delivery.
272272
///
273-
/// The following example shows an `AsyncThrowingStream` created with this
274-
/// initializer that produces random numbers on a one-second interval. When
275-
/// a private `keepRunning` variable becomes `false`, the inner `while` loop
276-
/// exits and the stream finishes. If the random number is divisble by 5 with
277-
/// no remainder, the stream throws a `MyRandomNumberError`.
273+
/// The following example shows an `AsyncStream` created with this
274+
/// initializer that produces 100 random numbers on a one-second interval,
275+
/// calling `yield(_:)` to deliver each element to the awaiting call point.
276+
/// When the `for` loop exits and the stream finishes by calling the
277+
/// continuation's `finish()` method. If the random number is divisble by 5
278+
/// with no remainder, the stream throws a `MyRandomNumberError`.
278279
///
279280
/// let stream = AsyncThrowingStream<Int, Error>(Int.self,
280281
/// bufferingPolicy: .bufferingNewest(5)) { continuation in
281282
/// Task.detached {
282-
/// while (keepRunning) {
283+
/// for _ in 0..<100 {
283284
/// await Task.sleep(1 * 1_000_000_000)
284285
/// let random = Int.random(in: 1...10)
285286
/// if (random % 5 == 0) {

0 commit comments

Comments
 (0)