@MainActor code not executed ?
Hi,
I managed to get some cool results with this great library.
However now I have a problem calling MainActor-isolated APIs (e.g. NSApplication.shared). Calling anything marked as @MainActor is stuck and doesn't get executed.
(vanilla node.js / swift 6)
import NodeAPI
@MainActor func f(a: Double) -> Double {
print("inside main actor") // <-- ❌ never gets printed
return a * 2
}
#NodeModule(exports: [
"f": try NodeFunction { () in
print("entering") // <-- ✅ printed
let b = await f(a: 3)
print("exiting") // <-- ❌ never gets printed
return b
}
])
Am I doing things wrong ? I checked #17 about concurrency and actors and #4 about RunLoop & DispatchQueue but couldn't use the answers to solve my problem. Here I absolutely need to switch execution to the MainActor. The final goal is to open a CoreGraphics window.
Hey! Have you found a solution?
This is indeed the same issue as #4 and more recently #51. I provided a non-optimal workaround in https://github.com/kabiroberai/node-swift/issues/51#issuecomment-2989558849 but will try to come up with a better solution when I have some time.