AFAICS this is being proposed in Foundation because the deadline being a Date
which is a Foundation
type. We should thoroughly examine this though, and it should not just automatically result in this clock landing in Foundation where Date conveniently exists today.
I worry a bit that when we get to implemented deadlines in the stdlib/concurrency we may find ourselfes wanting to use UTCClock in almost any real application dealing with deadlines cross process, as we'd be relying on the fact that both systems have a notion of UTC I think.
Specifically, an interesting example here is Go's Deadline and time.Time. That time is a bit "special" because:
In addition to the required “wall clock” reading, a Time may contain an optional reading of the current process's monotonic clock, to provide additional precision for comparison or subtraction. See the “Monotonic Clocks” section in the package documentation for details.
The reason I mention this isn't to do the weird two-clocks trick as Go does, but to highlight the necessity of the UTC clock. The UTC clock can be conveniently used when crossing machine boundaries and is especially useful for setting deadlines which will cross machines/devices, which is something we're interested in doing. Otherwise we'd have to do conversions to an UTC clock and again, be forced into pulling in Foundation for this one single type whenever we deal with this situation.
Have we thought about conversions from monotonic clocks to an UTCTime by the way?
Let's entertain this idea:
What if the concurrency library gained a UTCTime type that makes it clear it is not calendrical date, but is good enough for our UTC deadline needs? Along with the UTCClock which would use the UTCTime for its Instant.
~~
The original proposal says:
SE-0329: Clock, Instant, and Duration / Lowering of Date/UTCClock
Originally the proposal included a concept of lowering Date
to the standard library in addition to altering its storage from Double
to a Duration
. There were strong objections on a few fronts with this move which ultimately had convincing merit. The primary objection was to the name Date
; given that there was no additional contextual API within the standard library or concurrency library this meant that Date
could easily get confused with the concept of a calendrical date (which that type definitively is not). Additionally it was rightfully brought up that Date
is missing concepts of leap seconds (which has since been accepted and proposed as an alteration to Foundation) because we see the utility of that as an additional functionality to Date
.
Also in the original revisions of the proposal we had a concept of WallClock
. After much discussion we feel that the name wall clock is misleading since the type really represents a clock based on UTC (once Date
has a historical accounting of leap seconds). But furthermore, we feel that the general utility of scheduling via a UTC clock is not a common task and that a vast majority of clocks for scheduling are really things that transact either via a clock that time passes while the machine is asleep or a clock that time does not pass while the machine is asleep. That accounting means that we feel that the right home for UTCClock
is in a higher level framework for that specialized task along side the calendrical calculation APIs; which is Foundation.
The first part are valid improvements that still have merit -- we could have a new integer based type that is the time, accounts for leap seconds, and lives in the concurrency library.
The second part, about it not being "common" I'm not so convienced about, I do feel it definitely can be pretty common to set deadlines based on some UTC time, especially when crossing devices. And I've had specific requests from network teams to provide deadline APIs in Concurrency that will scale nicely beyond a single device. Others have shown already that other languages readily offer such clocks in the core of a language, and I do agree with this sentiment as well.
So I'd still like to consider having this be a standard library type, and if not, we have to be really clear about why not and what the impact will be on practical use of deadline APIs in Swift concurrency.