1
1
import JavaScriptKit
2
2
import _CJavaScriptEventLoop
3
3
import _CJavaScriptKit
4
- import Synchronization
5
4
6
5
// NOTE: `@available` annotations are semantically wrong, but they make it easier to develop applications targeting WebAssembly in Xcode.
7
6
@@ -143,16 +142,16 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable {
143
142
144
143
typealias swift_task_enqueueMainExecutor_hook_Fn = @convention ( thin) ( UnownedJob , swift_task_enqueueMainExecutor_original ) -> Void
145
144
let swift_task_enqueueMainExecutor_hook_impl : swift_task_enqueueMainExecutor_hook_Fn = { job, original in
146
- assert ( false )
147
145
JavaScriptEventLoop . shared. unsafeEnqueue ( job)
148
146
}
149
147
swift_task_enqueueMainExecutor_hook = unsafeBitCast ( swift_task_enqueueMainExecutor_hook_impl, to: UnsafeMutableRawPointer ? . self)
150
148
151
149
didInstallGlobalExecutor = true
152
150
}
153
151
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) , {
156
155
#if compiler(>=5.9)
157
156
job. runSynchronously ( on: self . asUnownedSerialExecutor ( ) )
158
157
#else
@@ -161,23 +160,6 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable {
161
160
} )
162
161
}
163
162
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
-
181
163
private func unsafeEnqueue( _ job: UnownedJob ) {
182
164
insertJobQueue ( job: job)
183
165
}
0 commit comments