Skip to content

Commit 284169e

Browse files
committed
struct Timeout -> TimeoutController
1 parent d0b93cf commit 284169e

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ let val = try await withThrowingTimeout(seconds: 2.0) {
4040

4141
> Note: When the timeout expires the task executing the closure is cancelled and `TimeoutError` is thrown.
4242
43-
An overload includes a `Timeout` object allowing the body to cancel or move the expiration where required:
43+
An overload includes a `TimeoutController` object allowing the body to cancel or move the expiration where required:
4444

4545
```swift
4646
try await withThrowingTimeout(seconds: 1.0) { timeout in

Sources/Timeout.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
#if compiler(>=6.0)
3333
import Foundation
3434

35-
public struct Timeout: Sendable {
35+
@available(*, unavailable, renamed: "TimeoutController")
36+
public typealias Timeout = TimeoutController
37+
38+
public struct TimeoutController: Sendable {
3639
fileprivate var canary: @Sendable () -> Void
3740
fileprivate let shared: SharedState
3841

@@ -74,7 +77,7 @@ public struct Timeout: Sendable {
7477
}
7578

7679
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
77-
public extension Timeout {
80+
public extension TimeoutController {
7881

7982
@discardableResult
8083
func expire<C: Clock>(
@@ -97,7 +100,7 @@ public extension Timeout {
97100
}
98101
}
99102

100-
extension Timeout {
103+
extension TimeoutController {
101104

102105
init(
103106
canary: @escaping @Sendable () -> Void,
@@ -156,13 +159,13 @@ extension Timeout {
156159
func withNonEscapingTimeout<T>(
157160
_ timeout: @escaping @Sendable () async throws -> Never,
158161
isolation: isolated (any Actor)? = #isolation,
159-
body: (Timeout) async throws -> sending T
162+
body: (TimeoutController) async throws -> sending T
160163
) async throws -> sending T {
161164
// canary ensuring Timeout does not escape at runtime.
162165
// Swift 6.2 and later enforce at compile time with ~Escapable
163166
try await withoutActuallyEscaping({ @Sendable in }) { escaping in
164167
_ = isolation
165-
let timeout = Timeout(canary: escaping, pending: timeout)
168+
let timeout = TimeoutController(canary: escaping, pending: timeout)
166169
return try await Transferring(body(timeout))
167170
}.value
168171
}

Sources/withThrowingTimeout.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public func withThrowingTimeout<T>(
5454
public func withThrowingTimeout<T>(
5555
isolation: isolated (any Actor)? = #isolation,
5656
seconds: TimeInterval,
57-
body: (Timeout) async throws -> sending T
57+
body: (TimeoutController) async throws -> sending T
5858
) async throws -> sending T {
5959
try await _withThrowingTimeout(isolation: isolation, body: body) {
6060
try await Task.sleep(nanoseconds: UInt64(seconds * 1_000_000_000))
@@ -91,7 +91,7 @@ public func withThrowingTimeout<T>(
9191

9292
private func _withThrowingTimeout<T>(
9393
isolation: isolated (any Actor)? = #isolation,
94-
body: (Timeout) async throws -> sending T,
94+
body: (TimeoutController) async throws -> sending T,
9595
timeout closure: @Sendable @escaping () async throws -> Never
9696
) async throws -> Transferring<T> {
9797
try await withoutActuallyEscaping(body) { escapingBody in

0 commit comments

Comments
 (0)