@@ -27,22 +27,33 @@ extension JavaScriptEventLoop: MainExecutor {
27
27
extension JavaScriptEventLoop : TaskExecutor { }
28
28
29
29
@available ( macOS 9999 , iOS 9999 , watchOS 9999 , tvOS 9999 , visionOS 9999 , * )
30
- extension JavaScriptEventLoop : SchedulableExecutor {
30
+ extension JavaScriptEventLoop : SchedulingExecutor {
31
31
public func enqueue< C: Clock > (
32
32
_ job: consuming ExecutorJob ,
33
33
after delay: C . Duration ,
34
34
tolerance: C . Duration ? ,
35
35
clock: C
36
36
) {
37
- let milliseconds = Self . delayInMilliseconds ( from: delay, clock: clock)
37
+ let duration : Duration
38
+ // Handle clocks we know
39
+ if let _ = clock as? ContinuousClock {
40
+ duration = delay as! ContinuousClock . Duration
41
+ } else if let _ = clock as? SuspendingClock {
42
+ duration = delay as! SuspendingClock . Duration
43
+ } else {
44
+ // Hand-off the scheduling work to Clock implementation for unknown clocks
45
+ clock. enqueue ( job, on: self , at: clock. now. advanced ( by: delay) ,
46
+ tolerance: tolerance)
47
+ return
48
+ }
49
+ let milliseconds = Self . delayInMilliseconds ( from: duration)
38
50
self . enqueue (
39
51
UnownedJob ( job) ,
40
52
withDelay: milliseconds
41
53
)
42
54
}
43
55
44
- private static func delayInMilliseconds< C: Clock > ( from duration: C . Duration , clock: C ) -> Double {
45
- let swiftDuration = clock. convert ( from: duration) !
56
+ private static func delayInMilliseconds( from swiftDuration: Duration ) -> Double {
46
57
let ( seconds, attoseconds) = swiftDuration. components
47
58
return Double ( seconds) * 1_000 + ( Double ( attoseconds) / 1_000_000_000_000_000 )
48
59
}
@@ -52,7 +63,7 @@ extension JavaScriptEventLoop: SchedulableExecutor {
52
63
@available ( macOS 9999 , iOS 9999 , watchOS 9999 , tvOS 9999 , visionOS 9999 , * )
53
64
extension JavaScriptEventLoop : ExecutorFactory {
54
65
// Forward all operations to the current thread's JavaScriptEventLoop instance
55
- final class CurrentThread : TaskExecutor , SchedulableExecutor , MainExecutor , SerialExecutor {
66
+ final class CurrentThread : TaskExecutor , SchedulingExecutor , MainExecutor , SerialExecutor {
56
67
func checkIsolated( ) { }
57
68
58
69
func enqueue( _ job: consuming ExecutorJob ) {
0 commit comments