I make macOS application. For some reason (maybe c...
# kotlin-native
a
I make macOS application. For some reason (maybe coroutines bug) I’ve replace _`app.run()` (_app = NSApplication.sharedApplication) to
Copy code
app.finishLaunching()
while (active.value) {
    app.nextEventMatchingMask(NSEventMaskAny, null, NSDefaultRunLoopMode, true)?.let {
        app.sendEvent(it)
    }
    runBlocking {
        delay(100.milliseconds)
    }
}
But now hotkeys (cmd+Q) and window’s button
close
don’t work. How can I process this events manually in macOS code? In main cycle? In Controller? In some
NSWindow
field?
j
What happens when you use the normal
app.run()
runloop?
a
The ktor-client-curl works very slowly - 10 sec per request instead of 500ms
j
Can I see that code ktor-client code? Are you dispatching the request on a background queue/thread, then updating UI on main thread?
Wild guess based on current info: If the UI is updated on a background thread, it will happen very slowly.
a
I use many Workers with own
newSingleThreadContext
and run
app.run()
in the main thread.
j
and if you update the UI with the results of one of these calls, that's on the main thread too?
You can get back on the main thread using:
Copy code
DispatchQueue.main.async { 
  // your code here
}
^-- that's Swift, Kotlin equivalent must be similar (or same).
If yes to above, then it shouldn't be taking 10 seconds for those tasks.
If no to above, then it probably isn't taking 10 seconds, but the update of the UI is.
a
I haven’t problem with UI. I have problem with another thread and ktor-client request in it. This thread do something and write the result into
AtomicReference
. Later -
delay
and perform next request. If I use
app.run
- request works 10 seconds. If don’t use - 0.3..0.5 seconds.
j
OK, hopefully someone can help with that.
a