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

geesawra.industries/old-fella

Old people's social media app

0
1
main
25 lines · 642 B Raw History
import Observation
import XCTest

@testable import OldFella

actor ThreadGate {
    private var continuation: CheckedContinuation<Void, Never>?
    private var started: CheckedContinuation<Void, Never>?
    private var isWaiting = false
    func wait() async {
        isWaiting = true
        started?.resume()
        started = nil
        await withCheckedContinuation { continuation = $0 }
    }
    func waitUntilStarted() async {
        if isWaiting { return }
        await withCheckedContinuation { started = $0 }
    }
    func release() {
        continuation?.resume()
        continuation = nil
        isWaiting = false
    }
}