@@ -42,18 +42,16 @@ import Foundation
42
42
/// - ``wait()``
43
43
/// - ``waitUnlessCancelled()``
44
44
public final class AsyncSemaphore : @unchecked Sendable {
45
- /// The `Suspension` class holds the state of one given call to a
46
- /// waiting method.
45
+ /// `Suspension` is the state of a task waiting for a signal.
47
46
///
48
47
/// It is a class because instance identity helps `waitUnlessCancelled()`
49
48
/// deal with both early and late cancellation.
50
49
///
51
- /// The private `Suspension` class is not really Sendable. But we make
52
- /// it @unchecked Sendable in order to prevent compiler warnings:
53
- /// the suspension state is always protected by the semaphore `_lock`.
50
+ /// We make it @unchecked Sendable in order to prevent compiler warnings:
51
+ /// instances are always protected by the semaphore's lock.
54
52
private class Suspension : @unchecked Sendable {
55
53
enum State {
56
- /// Initial state. Next is suspended , or cancelled.
54
+ /// Initial state. Next is suspendedUnlessCancelled , or cancelled.
57
55
case pending
58
56
59
57
/// Waiting for a signal, with support for cancellation.
@@ -79,9 +77,6 @@ public final class AsyncSemaphore: @unchecked Sendable {
79
77
private var value : Int
80
78
81
79
/// As many elements as there are suspended tasks waiting for a signal.
82
- /// We store `Suspension` instances instead of `UnsafeContinuation`, because
83
- /// we support cancellation by removing `Suspension` instances from
84
- /// this array.
85
80
private var suspensions : [ Suspension ] = [ ]
86
81
87
82
/// The lock that protects `value` and `suspensions`.
0 commit comments