Skip to content

Commit 48e8916

Browse files
committed
Address PR feedback
1 parent 5d9aa13 commit 48e8916

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

Sources/JavaScriptEventLoop/JavaScriptEventLoop+ExecutorFactory.swift

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@_spi(ExperimentalCustomExecutors) @_spi(ExperimentalScheduling) import _Concurrency
99
#else
1010
import _Concurrency
11-
#endif
11+
#endif // #if compiler(>=6.3)
1212
import _CJavaScriptKit
1313

1414
#if compiler(>=6.3)
@@ -40,7 +40,22 @@ extension JavaScriptEventLoop: SchedulingExecutor {
4040
tolerance: C.Duration?,
4141
clock: C
4242
) {
43-
#if !hasFeature(Embedded)
43+
#if hasFeature(Embedded)
44+
#if compiler(>=6.4)
45+
// In Embedded Swift, ContinuousClock and SuspendingClock are unavailable.
46+
// Hand-off the scheduling work to the Clock implementation for custom clocks.
47+
clock.enqueue(
48+
job,
49+
on: self,
50+
at: clock.now.advanced(by: delay),
51+
tolerance: tolerance
52+
)
53+
#else
54+
fatalError(
55+
"Delayed enqueue requires Swift 6.4+ in Embedded mode"
56+
)
57+
#endif // #if compiler(>=6.4) (Embedded)
58+
#else // #if hasFeature(Embedded)
4459
let duration: Duration
4560
// Handle clocks we know
4661
if let _ = clock as? ContinuousClock {
@@ -60,16 +75,14 @@ extension JavaScriptEventLoop: SchedulingExecutor {
6075
return
6176
#else
6277
fatalError("Unsupported clock type; only ContinuousClock and SuspendingClock are supported")
63-
#endif
78+
#endif // #if compiler(>=6.4) (non-Embedded)
6479
}
6580
let milliseconds = Self.delayInMilliseconds(from: duration)
6681
self.enqueue(
6782
UnownedJob(job),
6883
withDelay: milliseconds
6984
)
70-
#else
71-
fatalError("SchedulingExecutor.enqueue is not supported in embedded mode")
72-
#endif
85+
#endif // #if hasFeature(Embedded)
7386
}
7487

7588
private static func delayInMilliseconds(from swiftDuration: Duration) -> Double {
@@ -90,7 +103,6 @@ extension JavaScriptEventLoop: ExecutorFactory {
90103
JavaScriptEventLoop.shared.enqueue(job)
91104
}
92105

93-
#if !hasFeature(Embedded)
94106
func enqueue<C: Clock>(
95107
_ job: consuming ExecutorJob,
96108
after delay: C.Duration,
@@ -104,7 +116,6 @@ extension JavaScriptEventLoop: ExecutorFactory {
104116
clock: clock
105117
)
106118
}
107-
#endif
108119
func run() throws {
109120
try JavaScriptEventLoop.shared.run()
110121
}
@@ -122,4 +133,4 @@ extension JavaScriptEventLoop: ExecutorFactory {
122133
}
123134
}
124135

125-
#endif // compiler(>=6.3)
136+
#endif // #if compiler(>=6.3)

0 commit comments

Comments
 (0)