Skip to content

Commit

Permalink
preserve TimeoutError
Browse files Browse the repository at this point in the history
  • Loading branch information
swhitty committed Sep 8, 2024
1 parent 19228ac commit 1896b58
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions Sources/Timeout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,12 @@ private func _withThrowingTimeout<T>(
bodyTask.cancel()
}
timeoutTask.cancel()
let timeoutResult = await timeoutTask.result

switch bodyResult {
case .success(let bodySuccess):
return bodySuccess
case .failure(let bodyError):
if case .failure(let timeoutError) = timeoutResult, timeoutError is TimeoutError {
throw timeoutError
} else {
throw bodyError
}
if case .failure(let timeoutError) = await timeoutTask.result,
timeoutError is TimeoutError {
throw timeoutError
} else {
return try bodyResult.get()
}
}
}
Expand Down

0 comments on commit 1896b58

Please sign in to comment.