11import JavaScriptKit
22import _CJavaScriptEventLoop
33import _CJavaScriptKit
4- import Synchronization
54
65// NOTE: `@available` annotations are semantically wrong, but they make it easier to develop applications targeting WebAssembly in Xcode.
76
@@ -143,16 +142,16 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable {
143142
144143 typealias swift_task_enqueueMainExecutor_hook_Fn = @convention ( thin) ( UnownedJob , swift_task_enqueueMainExecutor_original ) -> Void
145144 let swift_task_enqueueMainExecutor_hook_impl : swift_task_enqueueMainExecutor_hook_Fn = { job, original in
146- assert ( false )
147145 JavaScriptEventLoop . shared. unsafeEnqueue ( job)
148146 }
149147 swift_task_enqueueMainExecutor_hook = unsafeBitCast ( swift_task_enqueueMainExecutor_hook_impl, to: UnsafeMutableRawPointer ? . self)
150148
151149 didInstallGlobalExecutor = true
152150 }
153151
154- func enqueue( _ job: UnownedJob , withDelay nanoseconds: UInt64 ) {
155- enqueue ( withDelay: nanoseconds, job: {
152+ private func enqueue( _ job: UnownedJob , withDelay nanoseconds: UInt64 ) {
153+ let milliseconds = nanoseconds / 1_000_000
154+ setTimeout ( Double ( milliseconds) , {
156155 #if compiler(>=5.9)
157156 job. runSynchronously ( on: self . asUnownedSerialExecutor ( ) )
158157 #else
@@ -161,23 +160,6 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable {
161160 } )
162161 }
163162
164- func enqueue( withDelay nanoseconds: UInt64 , job: @escaping ( ) -> Void ) {
165- let milliseconds = nanoseconds / 1_000_000
166- setTimeout ( Double ( milliseconds) , job)
167- }
168-
169- func enqueue(
170- withDelay seconds: Int64 , _ nanoseconds: Int64 ,
171- _ toleranceSec: Int64 , _ toleranceNSec: Int64 ,
172- _ clock: Int32 , job: @escaping ( ) -> Void
173- ) {
174- var nowSec : Int64 = 0
175- var nowNSec : Int64 = 0
176- swift_get_time ( & nowSec, & nowNSec, clock)
177- let delayNanosec = ( seconds - nowSec) * 1_000_000_000 + ( nanoseconds - nowNSec)
178- enqueue ( withDelay: delayNanosec <= 0 ? 0 : UInt64 ( delayNanosec) , job: job)
179- }
180-
181163 private func unsafeEnqueue( _ job: UnownedJob ) {
182164 insertJobQueue ( job: job)
183165 }
0 commit comments