Skip to content

Commit b92ec84

Browse files
committed
Enhance implementation comments
1 parent f1c4a0a commit b92ec84

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

Sources/Semaphore/AsyncSemaphore.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,16 @@ import Foundation
4242
/// - ``wait()``
4343
/// - ``waitUnlessCancelled()``
4444
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.
4746
///
4847
/// It is a class because instance identity helps `waitUnlessCancelled()`
4948
/// deal with both early and late cancellation.
5049
///
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.
5452
private class Suspension: @unchecked Sendable {
5553
enum State {
56-
/// Initial state. Next is suspended, or cancelled.
54+
/// Initial state. Next is suspendedUnlessCancelled, or cancelled.
5755
case pending
5856

5957
/// Waiting for a signal, with support for cancellation.
@@ -79,9 +77,6 @@ public final class AsyncSemaphore: @unchecked Sendable {
7977
private var value: Int
8078

8179
/// 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.
8580
private var suspensions: [Suspension] = []
8681

8782
/// The lock that protects `value` and `suspensions`.

0 commit comments

Comments
 (0)