Skip to content

Commit 8a8a649

Browse files
committed
Embedded Swift fixes
1 parent 3b4bba1 commit 8a8a649

1 file changed

Lines changed: 7 additions & 16 deletions

File tree

Sources/JavaScriptEventLoop/JavaScriptEventLoop+ExecutorFactory.swift

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,13 @@ extension JavaScriptEventLoop: SchedulingExecutor {
4040
tolerance: C.Duration?,
4141
clock: C
4242
) {
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-
)
43+
#if $Embedded
44+
// ContinuousClock and SuspendingClock are unavailable in Embedded Swift,
45+
// but Swift.Duration is, and every standard clock uses it.
46+
guard let duration = delay as? Duration else {
47+
fatalError("Unsupported clock type; only Duration-based clocks are supported in Embedded Swift")
48+
}
5349
#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)
5950
let duration: Duration
6051
if let _ = clock as? ContinuousClock {
6152
duration = delay as! ContinuousClock.Duration
@@ -64,12 +55,12 @@ extension JavaScriptEventLoop: SchedulingExecutor {
6455
} else {
6556
fatalError("Unsupported clock type; only ContinuousClock and SuspendingClock are supported")
6657
}
58+
#endif
6759
let milliseconds = Self.delayInMilliseconds(from: duration)
6860
self.enqueue(
6961
UnownedJob(job),
7062
withDelay: milliseconds
7163
)
72-
#endif // #if hasFeature(Embedded)
7364
}
7465

7566
private static func delayInMilliseconds(from swiftDuration: Duration) -> Double {

0 commit comments

Comments
 (0)