mirror of
https://github.com/aculix/knotchy.git
synced 2026-10-27 07:15:53 +00:00
20 lines
635 B
Swift
20 lines
635 B
Swift
import Testing
|
|
|
|
/// For work on other executors; controller timers run on the `TestClock` and never need it.
|
|
@MainActor
|
|
func waitUntil(
|
|
_ description: String,
|
|
timeout: Duration = .seconds(5),
|
|
sourceLocation: SourceLocation = #_sourceLocation,
|
|
_ condition: @MainActor () -> Bool
|
|
) async {
|
|
let deadline = ContinuousClock.now + timeout
|
|
while !condition() {
|
|
if ContinuousClock.now >= deadline {
|
|
Issue.record("Timed out waiting until \(description)", sourceLocation: sourceLocation)
|
|
return
|
|
}
|
|
do { try await Task.sleep(for: .milliseconds(1)) } catch { return }
|
|
}
|
|
}
|