Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
swhitty committed Sep 15, 2024
1 parent e7f38fe commit 0e350e8
Showing 1 changed file with 0 additions and 34 deletions.
34 changes: 0 additions & 34 deletions FlyingSocks/Sources/Task+Timeout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,6 @@ public struct TimeoutError: LocalizedError {
}
}

#if compiler(>=6.0)
package func withThrowingTimeout<T>(
isolation: isolated (any Actor)? = #isolation,
seconds: TimeInterval,
body: () async throws -> sending T
) async throws -> sending T {
try await withoutActuallyEscaping(body) { escapingBody in
let bodyTask = Task {
defer { _ = isolation }
return try await Transferring(escapingBody())
}
let timeoutTask = Task {
defer { bodyTask.cancel() }
try await Task.sleep(nanoseconds: UInt64(seconds * 1_000_000_000))
throw TimeoutError("Task timed out before completion. Timeout: \(seconds) seconds.")
}

let bodyResult = await withTaskCancellationHandler {
await bodyTask.result
} onCancel: {
bodyTask.cancel()
}
timeoutTask.cancel()

if case .failure(let timeoutError) = await timeoutTask.result,
timeoutError is TimeoutError {
throw timeoutError
} else {
return try bodyResult.get()
}
}.value
}
#else
package func withThrowingTimeout<T>(
seconds: TimeInterval,
body: () async throws -> T
Expand Down Expand Up @@ -104,7 +71,6 @@ private func _withThrowingTimeout<T: Sendable>(
return success
}
}
#endif

package extension Task {

Expand Down

0 comments on commit 0e350e8

Please sign in to comment.