Skip to content

Commit

Permalink
Remove enqueueMainJob
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Jun 27, 2024
1 parent a0c4602 commit 888de17
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable {

typealias swift_task_enqueueMainExecutor_hook_Fn = @convention(thin) (UnownedJob, swift_task_enqueueMainExecutor_original) -> Void
let swift_task_enqueueMainExecutor_hook_impl: swift_task_enqueueMainExecutor_hook_Fn = { job, original in
JavaScriptEventLoop.enqueueMainJob(job)
JavaScriptEventLoop.shared.unsafeEnqueue(job)
}
swift_task_enqueueMainExecutor_hook = unsafeBitCast(swift_task_enqueueMainExecutor_hook_impl, to: UnsafeMutableRawPointer?.self)

Expand Down Expand Up @@ -188,21 +188,6 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable {
public func asUnownedSerialExecutor() -> UnownedSerialExecutor {
return UnownedSerialExecutor(ordinary: self)
}

public static func enqueueMainJob(_ job: consuming ExecutorJob) {
self.enqueueMainJob(UnownedJob(job))
}

static func enqueueMainJob(_ job: UnownedJob) {
let currentEventLoop = JavaScriptEventLoop.shared
if currentEventLoop === JavaScriptEventLoop.mainThreadEventLoop {
currentEventLoop.unsafeEnqueue(job)
} else {
// Notify the main thread to execute the job
let jobBitPattern = unsafeBitCast(job, to: UInt.self)
_ = JSObject.global.postMessage!(jobBitPattern)
}
}
}

#if compiler(>=5.7)
Expand Down

0 comments on commit 888de17

Please sign in to comment.