Skip to content

Commit e3181b0

Browse files
committedJul 6, 2024·
Revert debug changes in JavaScriptEventLoop
1 parent 91258e2 commit e3181b0

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed
 

Diff for: ‎Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift

+3-21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import JavaScriptKit
22
import _CJavaScriptEventLoop
33
import _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
}

Diff for: ‎Sources/JavaScriptEventLoop/JobQueue.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import _CJavaScriptEventLoop
99
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
1010
struct QueueState: Sendable {
1111
fileprivate var headJob: UnownedJob? = nil
12-
var isSpinning: Bool = false
12+
fileprivate var isSpinning: Bool = false
1313
}
1414

1515
@available(macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0, *)

0 commit comments

Comments
 (0)
Please sign in to comment.