Skip to content

Commit 77f02fc

Browse files
committed
Yield TimeoutError before cancelling body task in withTimeout
Otherwise, the body task might finish before we yield the `TimeoutError` and thus `withTimeout` would not actually throw a `TimeoutError`. rdar://137171114
1 parent dd95a3d commit 77f02fc

File tree

2 files changed

+1
-2
lines changed

2 files changed

+1
-2
lines changed

Sources/SKTestSupport/RepeatUntilExpectedResult.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ package func repeatUntilExpectedResult(
2626
file: StaticString = #filePath,
2727
line: UInt = #line
2828
) async throws {
29-
logger.info("x: \(Int(timeout.seconds / sleepInterval.seconds))")
3029
for _ in 0..<Int(timeout.seconds / sleepInterval.seconds) {
3130
if try await body() {
3231
return

Sources/SwiftExtensions/AsyncUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ package func withTimeout<T: Sendable>(
189189

190190
let timeoutTask = Task {
191191
try await Task.sleep(for: duration)
192-
bodyTask.cancel()
193192
continuation.yield(with: .failure(TimeoutError()))
193+
bodyTask.cancel()
194194
}
195195
mutableTasks = [bodyTask, timeoutTask]
196196
}

0 commit comments

Comments
 (0)