Questions tagged «ktor»

3
withTimeout函数提供IllegalStateException:没有事件循环。使用runBlocking {…}启动一个。在Kotlin Multiplatform iOS客户端中
更新:如果我先执行没有超时的协程,然后执行withTimeout,它将起作用。但是,如果我先用timeout执行协程,则会给我一个错误。异步也是如此。 我正在创建一个演示kotlin跨平台应用程序,并在其中使用ktor执行API调用。我想在ktor请求上具有可配置的超时功能,所以我在协程级别使用withTimeout。 这是我使用网络API进行的函数调用。 suspend fun <T> onNetworkWithTimeOut( url: String, timeoutInMillis: Long, block: suspend CoroutineScope.() -> Any): T { return withTimeout(timeoutInMillis) { withContext(dispatchers.io, block) } as T } suspend fun <T> onNetworkWithoutTimeOut(url: String, block: suspend CoroutineScope.() -> Any): T { return withContext(dispatchers.io, block) as T } 这是我的iOSMain模块的AppDispatcher类。 @InternalCoroutinesApi actual class AppDispatchersImpl …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.