Skip to content

Commit c446f4c

Browse files
committed
review followup
1 parent 8b2253c commit c446f4c

File tree

2 files changed

+76
-19
lines changed

2 files changed

+76
-19
lines changed

stdlib/public/Concurrency/CheckedContinuation.swift

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,32 @@ extension CheckedContinuation {
252252
}
253253
}
254254

255-
/// Invokes the passed in closure and provides with a checked continuation for the current task.
255+
/// Invokes the passed in closure with a checked continuation for the current task.
256+
///
256257
/// The body of the closure executes synchronously on the calling task, and once it returns
257258
/// the calling task is suspended. It is possible to immediately resume the task, or escape the
258-
/// continuation in order to complete it afterwards, and thus resuming the suspended task.
259+
/// continuation in order to complete it afterwards, which will them resume suspended task.
260+
///
261+
/// You must invoke the continuation's `resume` method exactly once.
262+
///
263+
/// Missing to invoke it (eventually) will cause the calling task to remain suspended
264+
/// indefinitely which will result in the task "hanging" as well as being leaked with
265+
/// no possibility to destroy it.
266+
///
267+
/// The checked continuation offers detection of mis-use, and dropping the last reference
268+
/// to it, without having resumed it will trigger a warning. Resuming a continuation twice
269+
/// is also diagnosed and will cause a crash.
259270
///
260271
/// - Parameters:
261272
/// - function: A string identifying the declaration that is the notional
262273
/// source for the continuation, used to identify the continuation in
263274
/// runtime diagnostics related to misuse of this continuation.
264275
/// - body: A closure that takes a `CheckedContinuation` parameter.
265-
/// You must resume the continuation exactly once.
276+
/// - Returns: The value continuation is resumed with.
277+
///
278+
/// - SeeAlso: `withCheckedThrowingContinuation(function:_:)`
279+
/// - SeeAlso: `withUnsafeContinuation(function:_:)`
280+
/// - SeeAlso: `withUnsafeThrowingContinuation(function:_:)`
266281
@available(SwiftStdlib 5.1, *)
267282
@_unsafeInheritExecutor // ABI compatibility with Swift 5.1
268283
@inlinable
@@ -275,20 +290,34 @@ public func withCheckedContinuation<T>(
275290
}
276291
}
277292

278-
/// Invokes the passed in closure and provides with a checked throwing continuation for the current task.
293+
/// Invokes the passed in closure with a checked continuation for the current task.
294+
///
279295
/// The body of the closure executes synchronously on the calling task, and once it returns
280296
/// the calling task is suspended. It is possible to immediately resume the task, or escape the
281-
/// continuation in order to complete it afterwards, and thus resuming the suspended task.
297+
/// continuation in order to complete it afterwards, which will them resume suspended task.
298+
///
299+
/// If `resume(throwing:)` is called on the continuation, this function throws that error.
300+
///
301+
/// You must invoke the continuation's `resume` method exactly once.
302+
///
303+
/// Missing to invoke it (eventually) will cause the calling task to remain suspended
304+
/// indefinitely which will result in the task "hanging" as well as being leaked with
305+
/// no possibility to destroy it.
306+
///
307+
/// The checked continuation offers detection of mis-use, and dropping the last reference
308+
/// to it, without having resumed it will trigger a warning. Resuming a continuation twice
309+
/// is also diagnosed and will cause a crash.
282310
///
283311
/// - Parameters:
284312
/// - function: A string identifying the declaration that is the notional
285313
/// source for the continuation, used to identify the continuation in
286314
/// runtime diagnostics related to misuse of this continuation.
287315
/// - body: A closure that takes a `CheckedContinuation` parameter.
288-
/// You must resume the continuation exactly once.
316+
/// - Returns: The value continuation is resumed with.
289317
///
290-
/// If `resume(throwing:)` is called on the continuation,
291-
/// this function throws that error.
318+
/// - SeeAlso: `withCheckedContinuation(function:_:)`
319+
/// - SeeAlso: `withUnsafeContinuation(function:_:)`
320+
/// - SeeAlso: `withUnsafeThrowingContinuation(function:_:)`
292321
@available(SwiftStdlib 5.1, *)
293322
@_unsafeInheritExecutor // ABI compatibility with Swift 5.1
294323
@inlinable

stdlib/public/Concurrency/PartialAsyncTask.swift

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,30 @@ internal func _resumeUnsafeThrowingContinuationWithError<T>(
293293

294294
#endif
295295

296-
/// Invokes the passed in closure and provides with an unsafe continuation for the current task.
296+
297+
/// Invokes the passed in closure with a unsafe continuation for the current task.
298+
///
297299
/// The body of the closure executes synchronously on the calling task, and once it returns
298300
/// the calling task is suspended. It is possible to immediately resume the task, or escape the
299-
/// continuation in order to complete it afterwards, and thus resuming the suspended task.
301+
/// continuation in order to complete it afterwards, which will them resume suspended task.
302+
///
303+
/// You must invoke the continuation's `resume` method exactly once.
304+
///
305+
/// Missing to invoke it (eventually) will cause the calling task to remain suspended
306+
/// indefinitely which will result in the task "hanging" as well as being leaked with
307+
/// no possibility to destroy it.
308+
///
309+
/// Unlike the "checked" continuation variant, the `UnsafeContinuation` does not
310+
/// detect or diagnose any kind of misuse, so you need to be extra careful to avoid
311+
/// calling `resume` twice or forgetting to call resume before letting go of the
312+
/// continuation object.
300313
///
301314
/// - Parameter fn: A closure that takes an `UnsafeContinuation` parameter.
302-
/// You must resume the continuation exactly once.
315+
/// - Returns: The value continuation is resumed with.
303316
///
304-
/// - Returns: The value passed to the continuation by the closure.
317+
/// - SeeAlso: `withUnsafeThrowingContinuation(function:_:)`
318+
/// - SeeAlso: `withCheckedContinuation(function:_:)`
319+
/// - SeeAlso: `withCheckedThrowingContinuation(function:_:)`
305320
@available(SwiftStdlib 5.1, *)
306321
@_unsafeInheritExecutor
307322
@_alwaysEmitIntoClient
@@ -313,18 +328,31 @@ public func withUnsafeContinuation<T>(
313328
}
314329
}
315330

316-
/// Invokes the passed in closure and provides with a unsafe throwing continuation for the current task.
331+
/// Invokes the passed in closure with a unsafe continuation for the current task.
332+
///
317333
/// The body of the closure executes synchronously on the calling task, and once it returns
318334
/// the calling task is suspended. It is possible to immediately resume the task, or escape the
319-
/// continuation in order to complete it afterwards, and thus resuming the suspended task.
335+
/// continuation in order to complete it afterwards, which will them resume suspended task.
320336
///
321-
/// - Parameter fn: A closure that takes an `UnsafeContinuation` parameter.
322-
/// You must resume the continuation exactly once.
337+
/// If `resume(throwing:)` is called on the continuation, this function throws that error.
338+
///
339+
/// You must invoke the continuation's `resume` method exactly once.
340+
///
341+
/// Missing to invoke it (eventually) will cause the calling task to remain suspended
342+
/// indefinitely which will result in the task "hanging" as well as being leaked with
343+
/// no possibility to destroy it.
323344
///
324-
/// - Returns: The value passed to the continuation by the closure.
345+
/// Unlike the "checked" continuation variant, the `UnsafeContinuation` does not
346+
/// detect or diagnose any kind of misuse, so you need to be extra careful to avoid
347+
/// calling `resume` twice or forgetting to call resume before letting go of the
348+
/// continuation object.
349+
///
350+
/// - Parameter fn: A closure that takes an `UnsafeContinuation` parameter.
351+
/// - Returns: The value continuation is resumed with.
325352
///
326-
/// If `resume(throwing:)` is called on the continuation,
327-
/// this function throws that error.
353+
/// - SeeAlso: `withUnsafeContinuation(function:_:)`
354+
/// - SeeAlso: `withCheckedContinuation(function:_:)`
355+
/// - SeeAlso: `withCheckedThrowingContinuation(function:_:)`
328356
@available(SwiftStdlib 5.1, *)
329357
@_unsafeInheritExecutor
330358
@_alwaysEmitIntoClient

0 commit comments

Comments
 (0)