Skip to content

Commit 88101f2

Browse files
Expose WebWorkerTaskExecutor when compiling with toolchain < 6.1
1 parent 02a4dda commit 88101f2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Diff for: Sources/JavaScriptEventLoop/WebWorkerTaskExecutor.swift

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
#if compiler(>=6.1) && _runtime(_multithreaded) // @_expose and @_extern are only available in Swift 6.1+
1+
#if compiler(>=6.0) // `TaskExecutor` is available since Swift 6.0
22

33
import JavaScriptKit
44
import _CJavaScriptKit
55
import _CJavaScriptEventLoop
66

7-
import Synchronization
7+
#if canImport(Synchronization)
8+
import Synchronization
9+
#endif
810
#if canImport(wasi_pthread)
911
import wasi_pthread
1012
import WASILibc
@@ -282,7 +284,7 @@ public final class WebWorkerTaskExecutor: TaskExecutor {
282284
}
283285

284286
func start(timeout: Duration, checkInterval: Duration) async throws {
285-
#if canImport(wasi_pthread)
287+
#if canImport(wasi_pthread) && _runtime(_multithreaded)
286288
class Context: @unchecked Sendable {
287289
let executor: WebWorkerTaskExecutor.Executor
288290
let worker: Worker
@@ -433,7 +435,7 @@ public final class WebWorkerTaskExecutor: TaskExecutor {
433435
///
434436
/// This function must be called once before using the Web Worker task executor.
435437
public static func installGlobalExecutor() {
436-
#if canImport(wasi_pthread)
438+
#if canImport(wasi_pthread) && _runtime(_multithreaded)
437439
// Ensure this function is called only once.
438440
guard _mainThread == nil else { return }
439441

@@ -471,7 +473,9 @@ public final class WebWorkerTaskExecutor: TaskExecutor {
471473
/// Enqueue a job scheduled from a Web Worker thread to the main thread.
472474
/// This function is called when a job is enqueued from a Web Worker thread.
473475
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
476+
#if compiler(>=6.1) // @_expose and @_extern are only available in Swift 6.1+
474477
@_expose(wasm, "swjs_enqueue_main_job_from_worker")
478+
#endif
475479
func _swjs_enqueue_main_job_from_worker(_ job: UnownedJob) {
476480
WebWorkerTaskExecutor.traceStatsIncrement(\.receiveJobFromWorkerThread)
477481
JavaScriptEventLoop.shared.enqueue(ExecutorJob(job))
@@ -480,15 +484,17 @@ func _swjs_enqueue_main_job_from_worker(_ job: UnownedJob) {
480484
/// Wake up the worker thread.
481485
/// This function is called when a job is enqueued from the main thread to a worker thread.
482486
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
487+
#if compiler(>=6.1) // @_expose and @_extern are only available in Swift 6.1+
483488
@_expose(wasm, "swjs_wake_worker_thread")
489+
#endif
484490
func _swjs_wake_worker_thread() {
485491
WebWorkerTaskExecutor.Worker.currentThread!.run()
486492
}
487493

488-
#endif
489-
490494
fileprivate func trace(_ message: String) {
491495
#if JAVASCRIPTKIT_TRACE
492496
JSObject.global.process.stdout.write("[trace tid=\(swjs_get_worker_thread_id())] \(message)\n")
493497
#endif
494498
}
499+
500+
#endif // compiler(>=6.0)

0 commit comments

Comments
 (0)