ktor client iOS hangs forever in runBlocking
See original GitHub issueexpect fun <T> runBlocking(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T
fun getGitHub(): HttpClientCall = runBlocking {
HttpClient().call("https://www.github.com")
}
actual fun <T> runBlocking(context: CoroutineContext, block: suspend CoroutineScope.() -> T): T {
return kotlinx.coroutines.runBlocking(context, block)
}
Xcode hangs forever when invoking the method:
func testRunBlocking() {
GitHubKt.getGitHub()
}
If I delete HttpClient
in runBlocking
then the method successfully returns a value on iOS.
Versions:
kotlin_version=1.3.0-rc-190
coroutines_version=1.0.0-RC1
ktor_version=1.0.0-beta-2
serialization_version=0.8.2-rc13
Is it a known issue that ktor iOS doesn’t work in runBlocking? Is this even a ktor issue or a coroutines issue? https://github.com/Kotlin/kotlinx.coroutines/issues/462
Issue Analytics
- State:
- Created 5 years ago
- Comments:20 (10 by maintainers)
Top Results From Across the Web
Ktor client unit test hangs / freezes within CoroutineScope. ...
The solution for me ended up being to run my tests within runBlocking() scope, and to inject its coroutineContext into my class to...
Read more >WhatsNew 1.6 | Ktor Framework
OkHttp and iOS: request with only-if-cache directive in Cache-Control ... WebSocket client closes connection due to an HTTP request timeout.
Read more >mutation attempt of frozen <object>@194c6a8 : KTOR-2947
I'm getting the same exception on iOS. Using the append function @Martynas Jegorovas uses above seems to have fixed it for me as...
Read more >Concurrency and coroutines
Get acquainted with the main concepts for using coroutines: Asynchronous vs. parallel processing. Dispatcher for changing threads. Frozen ...
Read more >Coroutines for Kotlin Multiplatform in Practise
Rapid Web API development with Kotlin and Ktor ... runBlocking(dispatcher) { runBlocking(dispatcher) { doWork() } } Works on iOS Deadlocks on JVM; 33....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I defined a custom
runBlocking
method using NSRunLoop and that works.https://github.com/bootstraponline/run_blocking/commit/a7953192c7078ab41dbf382f56bdc4432a46c84b#diff-c1a933ca71f0c706f65401b240f8c806
Well, running coroutines on background threads are not yet supported. Using runBlocking is quite dangerous. And for sure you can’t use runBlocking with MainLoopDispatcher and you are already on main loop. Are you sure you actually need blocking?