Skip to content

armgit / xtool

Public Imported from GitHub
0

Cross-platform Xcode replacement. Build and deploy iOS apps with SwiftPM on Linux, Windows, macOS.

641 B
Raw Blame
import Foundation
import Testing

/// Releases suspended reads on timeout so a regression cannot hang the test process.
func withInputTestTimeout<T>(
    _ timeout: Duration = .seconds(5),
    operation: () async throws -> T,
    cleanup: @escaping @Sendable () async -> Void,
) async throws -> T {
    let watchdog = Task {
        do {
            try await Task.sleep(for: timeout)
        } catch {
            return
        }
        Issue.record("Input operation exceeded timeout of \(timeout)")
        await cleanup()
    }
    defer {
        watchdog.cancel()
        await watchdog.value
    }
    return try await operation()
}