Open KishanBagaria opened 2 years ago
Reduced example:
import NodeAPI
import Foundation
@main struct AwesomeMod: NodeModule {
let exports: NodeValueConvertible
init() throws {
exports = try NodeFunction { _ in
DispatchQueue(label: "new-queue").async {
print("before queue")
DispatchQueue.main.sync {
print("inside queue")
}
print("after queue")
}
// RunLoop.main.run()
return NodeUndefined.deferred
}
}
}
This is happening because DispatchQueue.main.sync
enqueues the block onto the main NSRunLoop
. Vanilla Node doesn't have a running NSRunLoop
, whereas Electron is built to explicitly handle this case (see https://youtu.be/OPhb5GoV8Xk). You can sort of work around this by starting the RunLoop at the end of the function, though that causes it to never return. We should look into servicing the main run loop in a vanilla Node environment alongside libuv, as Electron does.