Why was `ContinuousClock` chosen as the default for `Task.sleep(for:)`?

Task.sleep(nanoseconds:) (aka the first Task.sleep(...) function introduced with Structured Concurrency) seems to respect actual system sleep, at least on macOS.

Once Clock/Instant/Duration was added to Swift later on, we got Task.sleep(for:tolerance:clock:). This function has a default value for clock: .continuous (ContinuousClock).

Task.sleep(nanoseconds:)'s behavior seems to be very similar to using Task.sleep(for:tolerance:clock:) with the (non-default) .suspendingclock (SuspendingClock). I should note that the documentation for Task.sleep(nanoseconds:) makes no mention of what it does when the system goes to sleep but after some testing this seems to be the case. Is its behavior (probably) platform-specific?

My gut reaction is that .suspending should have been the default clock chosen for these new Clock-based sleep functions. What do we think? Should we clarify the documentation of Task.sleep(nanoseconds:), or is this a non-issue for most people, or do folks just not realize the difference, etc.?

4 Likes