Cotton code
25 lines · 878 B · SwiftRaw
// How many calls to the core are on their way right now — the "no write in// flight" half of a quiet moment, which the Mac app waits for before it// relaunches itself onto a build installed under it (`SelfRelaunch`). Counted// where every call passes (`CottonCore.callRaw`), so no screen has to report// its own writes and none can forget to.import Foundationpublic final class CallsInFlight: @unchecked Sendable {    public static let shared = CallsInFlight()    private let lock = NSLock()    private var calls = 0    public init() {}    public var count: Int { lock.withLock { calls } }    /// Count `work` as in flight while it runs, however it ends.    public func during<T>(_ work: () async throws -> T) async rethrows -> T {        lock.withLock { calls += 1 }        defer { lock.withLock { calls -= 1 } }        return try await work()    }}