1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import Observation
import XCTest
@testable import OldFella
actor OverlapGate {
private var waits: [CheckedContinuation<Void, Never>] = []
private var observer: CheckedContinuation<Void, Never>?
func wait() async {
await withCheckedContinuation { continuation in
waits.append(continuation)
if waits.count == 2 {
observer?.resume()
observer = nil
}
}
}
func waitForCount(_ count: Int) async {
while waits.count < count { await Task.yield() }
}
func releaseFirst() { waits.removeFirst().resume() }
}