swift-timeout icon indicating copy to clipboard operation
swift-timeout copied to clipboard

Consider whether `ContinousClock` is the "correct" default clock

Open gregcotten opened this issue 6 months ago • 3 comments

Task.sleep(nanoseconds:) is used to sleep when calling withThrowingTimeout(seconds:). AFAICT Task.sleep(nanoseconds:) pauses on system sleep.

The withThrowingTimeout(after:) function uses a ContinousClock which is "A clock that measures time that always increments and does not stop incrementing while the system is asleep."

I think the withThrowingTimeout() functions that don't require a Clock parameter should all have the same behavior. Should ContinousClock change to SuspendingClock?

gregcotten avatar Jul 10 '25 16:07 gregcotten

I think this is a very valid suggestion and I agree that consistent behaviour is better here so it should switch to SuspendingClock

swhitty avatar Jul 11 '25 01:07 swhitty

Well Task.sleep(for:)'s default clock is .continuous, so it's maybe the right move to match that...

gregcotten avatar Jul 11 '25 03:07 gregcotten

I have asked in the Swift forums regarding why .continuous was chosen as the default, mostly for educational purposes, and perhaps to see if we can get better documentation regarding Task.sleep(nanoseconds:)

https://forums.swift.org/t/why-was-continuousclock-chosen-as-the-default-for-task-sleep-for/81047

gregcotten avatar Jul 11 '25 03:07 gregcotten