@@ -42,14 +42,9 @@ public protocol Clock<Duration>: Sendable {
42
42
func sleep( until deadline: Instant , tolerance: Instant . Duration ? ) async throws
43
43
#endif
44
44
45
- #if !$Embedded
46
- /// Choose which Dispatch clock to use with DispatchExecutor
47
- ///
48
- /// This controls which Dispatch clock is used to enqueue delayed jobs
49
- /// when using this Clock.
45
+ /// The traits associated with this clock instance.
50
46
@available ( SwiftStdlib 6 . 2 , * )
51
- var dispatchClockID : DispatchClockID { get }
52
- #endif
47
+ var traits : ClockTraits { get }
53
48
54
49
/// Convert a Clock-specific Duration to a Swift Duration
55
50
///
@@ -138,12 +133,6 @@ extension Clock {
138
133
139
134
@available ( SwiftStdlib 6 . 2 , * )
140
135
extension Clock {
141
- #if !$Embedded
142
- public var dispatchClockID : DispatchClockID {
143
- return . suspending
144
- }
145
- #endif
146
-
147
136
// For compatibility, return `nil` if this is not implemented
148
137
public func convert( from duration: Duration ) -> Swift . Duration ? {
149
138
return nil
@@ -198,6 +187,43 @@ extension Clock {
198
187
}
199
188
#endif
200
189
190
+ /// Represents traits of a particular Clock implementation.
191
+ ///
192
+ /// Clocks may be of a number of different varieties; executors will likely
193
+ /// have specific clocks that they can use to schedule jobs, and will
194
+ /// therefore need to be able to convert timestamps to an appropriate clock
195
+ /// when asked to enqueue a job with a delay or deadline.
196
+ ///
197
+ /// Choosing a clock in general requires the ability to tell which of their
198
+ /// clocks best matches the clock that the user is trying to specify a
199
+ /// time or delay in. Executors are expected to do this on a best effort
200
+ /// basis.
201
+ @available ( SwiftStdlib 6 . 2 , * )
202
+ public struct ClockTraits : OptionSet {
203
+ public let rawValue : Int32
204
+
205
+ public init ( rawValue: Int32 ) {
206
+ self . rawValue = rawValue
207
+ }
208
+
209
+ /// Clocks with this trait continue running while the machine is asleep.
210
+ public static let continuous = ClockTraits ( rawValue: 1 << 0 )
211
+
212
+ /// Indicates that a clock's time will only ever increase.
213
+ public static let monotonic = ClockTraits ( rawValue: 1 << 1 )
214
+
215
+ /// Clocks with this trait are tied to "wall time".
216
+ public static let wallTime = ClockTraits ( rawValue: 1 << 2 )
217
+ }
218
+
219
+ extension Clock {
220
+ /// The traits associated with this clock instance.
221
+ @available ( SwiftStdlib 6 . 2 , * )
222
+ var traits : ClockTraits {
223
+ return [ ]
224
+ }
225
+ }
226
+
201
227
enum _ClockID : Int32 {
202
228
case continuous = 1
203
229
case suspending = 2
0 commit comments