Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e13fc44

Browse files
committedDec 2, 2024·
Expose WebWorkerTaskExecutor when compiling with toolchain < 6.1
1 parent 02a4dda commit e13fc44

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed
 

‎Sources/JavaScriptEventLoop/WebWorkerTaskExecutor.swift

+10-4
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
@@ -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)
Please sign in to comment.