Hey! I am having trouble using the http client for...
# kotlin-native
m
Hey! I am having trouble using the http client for Kotlin/Native as given by https://github.com/e5l/http-client-common. I am getting a memory leak along with the error message ‘Uncaught exception from Kotlin's main: kotlin.IllegalStateException: There is no event loop. Use runBlocking { ... } to start one’. I do have runBlocking surrounding the calling code. Can anyone give me an example of how to use the client? My code is in the thread.
Copy code
// request created earlier

fun buttonPressed() {
    launch() {
        val response = net.getStatus(request = request)
        label.text = response.toString()
    }
}

suspend fun getStatus(httpRequest : HttpRequest) {

    val httpClient = HttpClient()

    return runBlocking {
        async {
            val response = httpClient.request(httpRequest)
            response.statusCode
        }.await()
    }
}
e
Did you use
runBlocking
in common code?
Please consider to follow the example on main page here: https://github.com/e5l/http-client-common
m
I am using Kotlin/Native for ios. I am writing my own wrapper and want to sort of return http response given httprequest. So, ideally, I would like to return the response inside the then block of promise or as above, write a suspending function to return the response.
t
@Mohit Gurumukhani you need to write own http client wrapper for blocking call