https://kotlinlang.org logo
Title
v

Vitaliy Kondratiev

11/22/2021, 3:03 PM
Hey guys. Starting to work with apollo3 and KMM. I'm wondering why this is an assertion during execution
assertMainThreadOnNative()
if I'm trying to execute a query. Why am I forced to do it on the main thread?
m

mbonnin

11/22/2021, 3:24 PM
Hi 👋 That's a long story with some details here. The tldr; is that when we started, multithreaded coroutines were super experimental and we wanted to make everything work with the regular coroutines artifact
Everything is still executed on a background thread so it hasn't been a big limitation so far.
Also, something else is that there is no blocking call with
NSUrlSession
so you get a callback in a dispatch queue from where you need to resume a coroutine.
If that coroutine is the main thread then it's easy to get
dispatch_main_queue()
. If it's not, then it's not the same story
v

Vitaliy Kondratiev

11/22/2021, 3:31 PM
wow thanks @mbonnin for the quick response. I'll take a look
m

mbonnin

11/22/2021, 3:32 PM
Sure thing. Let us know if you have a different use case, we can look into it.