Is calling Ktor in background thread possible at a...
# kotlin-native
a
Is calling Ktor in background thread possible at all ATM? We lost all hope to do that on iOS.
🚫 3
k
To be clear, if you call it on the main thread, the call suspends and does the actual network call on a background thread. Just FYI. It doesn’t actually do the network call on the main thread.
a
I understand. The issue is that we want to trigger network operation (it's sync data operation) from background thread (in Android service). So I can't switch to main thread (get illegal attempt to access non-shared $dispatch$lambda-0$FUNCTION_REFERENCE$42@85961ee8 from other thread) nor call Ktor in the background thread.
k
Yeah, got it. I’m currently wrestling with ktor/ios issues myself, so if there’s a vote for improving support, I’m a +1
a
I see, just wanted to confirm I didn't miss some magic how to workaround that. Sounds like we have to switch to platform impl on iOS for background part.
k
That’s pretty common
b
I'll work on expanding this, but here's a hacky approach for doing GET calls on background threads with native-mt that defers the responsibility of the network call to each platform. https://gist.github.com/brendanw/73067fdd7bec1e32ae936cd0c19bffa5