-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should Clock.sleep(for:) be added? #59914
Comments
|
It was in the accepted proposal, so I believe thats an omission -- right @phausler ? |
|
Specifically the proposal listed: extension Task {
@available(*, deprecated, renamed: "Task.sleep(for:)")
public static func sleep(_ duration: UInt64) async
@available(*, deprecated, renamed: "Task.sleep(for:)")
public static func sleep(nanoseconds duration: UInt64) async throws
public static func sleep(for: Duration) async throws
public static func sleep<C: Clock>(until deadline: C.Instant, tolerance: C.Instant.Duration? = nil, clock: C) async throws
}https://github.com/apple/swift-evolution/blob/main/proposals/0329-clock-instant-duration.md |
|
Correct, it was some of the very last iterations; the deprecations are obviously the next step but we can do those later to avoid churn. |
|
Unless I'm missing something in the proposal, it does not seem that Was it an oversight to not include |
|
Any update on this? Can this be added before Swift 5.7 is finalized? |
|
Just wanted to mention some concrete problems that arise from not having these functions. Since all APIs dealing with clocks and sleeping use instants, and not durations, it is not possible to use the APIs with a let clock: any Clock<Duration> = ContinuousClock()
try await clock.sleep(until: clock.now.advanced(by: .seconds(1)), tolerance: nil) // 🛑This is because the If we had the extension Clock {
func sleep(for duration: Self.Duration) async throws {
try await self.sleep(until: self.now.advanced(by: duration), tolerance: nil)
}
}
let clock: any Clock<Duration> = ContinuousClock()
try await clock.sleep(for: .seconds(1)) // ✅So, not having Is there anything I can do to help move this forward? I can easily create a PR to add these functions to the standard library if it doesn't require evolution. |
|
And one more thing to note. We definitely need the let clock: any Clock<Duration> = ContinuousClock()
try await Task.sleep(for: .seconds(1), clock: clock) // 🛑 |
|
Adding that function (to clock) would be an evolution type change. |
|
Ok, posted a pitch: https://forums.swift.org/t/pitch-clock-sleep-for/60376 |
|
The new and updated APIs from SE-0374 aren't available in Xcode 14.3 beta 2 (14E5207e). I tried using an Xcode playground for iOS; and an iOS project with a 16.4 minimum deployment. (Other APIs introduced in Swift 5.8 are available.) |
|
swiftlang/swift-evolution@419d000 -* Status: **Implemented (Swift 5.8)**
+* Status: **Implemented (Swift 5.9)** |
|
Yeah seems this'll come in 5.9, I think we can close this issue |
The
Clockproposal calls out 3 ways of sleeping, 2 onTaskand 1 onClock:However, there is no corresponding duration-based sleep for clocks:
This means in order to perform duration-based sleeping, which is usually more ergonomic, you have to resort to the longer
Task.sleepmethod:Should this 4th variation of sleep be added to the standard library to be consistent?
The text was updated successfully, but these errors were encountered: