Skip to content

Commit 7ce78d2

Browse files
committed
Fix concurrency @_spi
1 parent 83d886f commit 7ce78d2

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

Sources/JavaScriptEventLoop/JavaScriptEventLoop+ExecutorFactory.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// See: https://forums.swift.org/t/pitch-2-custom-main-and-global-executors/78437
66

77
#if compiler(>=6.3)
8-
@_spi(ExperimentalCustomExecutors) import _Concurrency
8+
@_spi(ExperimentalCustomExecutors) @_spi(ExperimentalScheduling) import _Concurrency
99
#else
1010
import _Concurrency
1111
#endif
@@ -42,6 +42,7 @@ extension JavaScriptEventLoop: SchedulingExecutor {
4242
) {
4343
let duration: Duration
4444
// Handle clocks we know
45+
#if !hasFeature(Embedded)
4546
if let _ = clock as? ContinuousClock {
4647
duration = delay as! ContinuousClock.Duration
4748
} else if let _ = clock as? SuspendingClock {
@@ -56,6 +57,9 @@ extension JavaScriptEventLoop: SchedulingExecutor {
5657
)
5758
return
5859
}
60+
#else
61+
fatalError("SchedulingExecutor.enqueue is not supported in embedded mode")
62+
#endif
5963
let milliseconds = Self.delayInMilliseconds(from: duration)
6064
self.enqueue(
6165
UnownedJob(job),
@@ -81,6 +85,7 @@ extension JavaScriptEventLoop: ExecutorFactory {
8185
JavaScriptEventLoop.shared.enqueue(job)
8286
}
8387

88+
#if !hasFeature(Embedded)
8489
func enqueue<C: Clock>(
8590
_ job: consuming ExecutorJob,
8691
after delay: C.Duration,
@@ -94,6 +99,7 @@ extension JavaScriptEventLoop: ExecutorFactory {
9499
clock: clock
95100
)
96101
}
102+
#endif
97103
func run() throws {
98104
try JavaScriptEventLoop.shared.run()
99105
}

Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,16 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable {
123123
private static func installGlobalExecutorIsolated() {
124124
guard !didInstallGlobalExecutor else { return }
125125
didInstallGlobalExecutor = true
126-
#if compiler(>=6.3)
126+
#if compiler(>=6.3) && !hasFeature(Embedded)
127127
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999, *) {
128128
// For Swift 6.3 and above, we can use the new `ExecutorFactory` API
129129
_Concurrency._createExecutors(factory: JavaScriptEventLoop.self)
130130
}
131131
#else
132-
// For Swift 6.1 and below, we need to install the global executor by hook API
132+
// For Swift 6.1 and below, or Embedded Swift, we need to install
133+
// the global executor by hook API. The ExecutorFactory mechanism
134+
// does not work in Embedded Swift because ExecutorImpl.swift is
135+
// excluded from the embedded Concurrency library.
133136
installByLegacyHook()
134137
#endif
135138
}

0 commit comments

Comments
 (0)