https://kotlinlang.org logo
#ktor
Title
# ktor
l

Leonid Golberg

02/11/2022, 9:34 AM
Hi All! Has anyone see this error:
Coroutines must be initialized from the main thread: call 'initMainThread' from the main thread first
?
I am launching raw socket API on iOS, ktor version
2.0.0-beta-1
e

e5l

02/11/2022, 9:41 AM
@Vsevolod Tolstopyatov [JB] could you help?
t

Thomas

02/11/2022, 10:48 AM
Yes I've seen it before. It happens if you call coroutines code for the first time on a background thread.
You could call coroutines code from a main thread first, which should solve the issue
l

Leonid Golberg

02/11/2022, 10:49 AM
So, workaround - call any coroutine on main thread?
Cool, thanks, I'll try!
t

Thomas

02/11/2022, 10:50 AM
Yes and after that you can use it from background threads
Don't forget to call initRuntimeIfNeeded() in your background thread too
🙏 1
l

Leonid Golberg

02/11/2022, 11:13 AM
Thanks, @Thomas this helped!
11 Views