@@ -27,22 +27,37 @@ 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 (
46
+ job,
47
+ on: self ,
48
+ at: clock. now. advanced ( by: delay) ,
49
+ tolerance: tolerance
50
+ )
51
+ return
52
+ }
53
+ let milliseconds = Self . delayInMilliseconds ( from: duration)
38
54
self . enqueue (
39
55
UnownedJob ( job) ,
40
56
withDelay: milliseconds
41
57
)
42
58
}
43
59
44
- private static func delayInMilliseconds< C: Clock > ( from duration: C . Duration , clock: C ) -> Double {
45
- let swiftDuration = clock. convert ( from: duration) !
60
+ private static func delayInMilliseconds( from swiftDuration: Duration ) -> Double {
46
61
let ( seconds, attoseconds) = swiftDuration. components
47
62
return Double ( seconds) * 1_000 + ( Double ( attoseconds) / 1_000_000_000_000_000 )
48
63
}
@@ -52,7 +67,7 @@ extension JavaScriptEventLoop: SchedulableExecutor {
52
67
@available ( macOS 9999 , iOS 9999 , watchOS 9999 , tvOS 9999 , visionOS 9999 , * )
53
68
extension JavaScriptEventLoop : ExecutorFactory {
54
69
// Forward all operations to the current thread's JavaScriptEventLoop instance
55
- final class CurrentThread : TaskExecutor , SchedulableExecutor , MainExecutor , SerialExecutor {
70
+ final class CurrentThread : TaskExecutor , SchedulingExecutor , MainExecutor , SerialExecutor {
56
71
func checkIsolated( ) { }
57
72
58
73
func enqueue( _ job: consuming ExecutorJob ) {
0 commit comments