~ knotless Search/
↑↓ move↵ open⇧↵ all results

geesawra.industries/old-fella

Old people's social media app

0
1
main
22 lines · 619 B Raw History
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() }
}