Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove enqueueMainJob
  • Loading branch information
kateinoigakukun committed Jun 27, 2024
commit 888de173f108a831aeb10d52727094f8b2fe3ec8
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