-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Adds sleep(for:) to clock #61222
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
Adds sleep(for:) to clock #61222
Conversation
9c42538
to
6b17d53
Compare
I think you'll need to rebase, so that the For consistency — and to avoid confusion with |
5d49f47
to
8c9d19e
Compare
Hi @benrimmington, I updated the PR to reflect the changes you mentioned. Let me know if you rather me move the |
@@ -156,8 +156,12 @@ extension Task where Success == Never, Failure == Never { | |||
/// - Parameter duration: The duration to wait. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation comments:
canceled
vscancelled
?- remove or expand
- Parameter
lists? - remove or update
on a continuous clock
? - remove
clock: .continuous
from example code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
canceled
vscancelled
?
These docs were copied from the other sleep methods, and they say "canceled". Perhaps OK to leave as-is and maybe all docs can be updated at some future time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Canceled" is the correct spelling in Apple docs, per longstanding practice and style guides dating back decades.
d67ad61
to
9794954
Compare
Hi @benrimmington, good catches, thanks! I've updated the PR. |
@swift-ci Please smoke test |
preset=stdlib_S_standalone_minimal_macho_x86_64,build,test |
@benrimmington I just realized that this PR was still in draft mode. I have just marked it as "ready for review." Sorry about that! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation here looks good to me.
Please create another PR for 5.8 as well! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing review pending a discussion about ABI stability of adding a default argument.
@@ -169,13 +172,18 @@ extension Task where Success == Never, Failure == Never { | |||
public static func sleep<C: Clock>( | |||
until deadline: C.Instant, | |||
tolerance: C.Instant.Duration? = nil, | |||
clock: C | |||
clock: C = ContinuousClock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that adding a default argument is not actually possible here, because the symbol that provides the default will not be available in library versions that predate the appearance of the default. @slavapestov, is that right?
If so, you should instead add an @_aEIC
overload that does not take a clock
parameter and calls this function with clock: ContinuousClock()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be misremembering, but I'd thought that it was the longstanding case that default arguments are emitted into the client and (thus) ABI stable to add?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, here we go: #56859 (comment)
Can do, but I'm not sure what that means. Do I just cherry pick these changes to the |
/// | ||
@available(SwiftStdlib 5.7, *) | ||
public static func sleep<C: Clock>( | ||
until deadline: C.Instant, | ||
tolerance: C.Instant.Duration? = nil, | ||
clock: C | ||
clock: C = ContinuousClock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here w.r.t. symbols in the library.
Yes, once we resolve the question I just raised, that's exactly the process. |
Please go ahead and create a cherry-pick to release/5.8, @mbrandonw. |
@mbrandonw Do you need any help with the |
Hi @benrimmington, sorry I didn't even realize this branch was merged. I will create the 5.8 PR right now! |
@benrimmington done! #62996 |
This adds a duration-based
sleep(for:)
method toClock
as an alternative to using the instant-basedsleep(until:)
method.Evolution proposal coming next, and here's a forum discussion.