Coroutines and Cannot use 'T' as reified type parameter

Hello, I have an object Ktor { where I have its methods like

        suspend fun <T>getAsync(url:String) = coroutineScope {
            println(url)
            return@coroutineScope httpClient.get<T>(url)
        }

But I can’t do this even if I wrap it in a class:

    class Get<T:Any>(){
        suspend fun getAsync(url:String) = coroutineScope {
            println(url)
            return@coroutineScope httpClient.get<T>(url)
        }
    }

So, the way I should do it according to the hint is to make an inline function:

    inline fun <reified T> get(url: String) = runBlocking {
        println(url)
        return@runBlocking httpClient.get<T>(url)
    }

But in this way I need to use runBlocking instead of coroutineScope.async.
There are 2 questions:

  1. How to make it properly?
  2. How much runBlocking can decrease the performance (especially with multiple HTTP requests)?

The way I can do it is to specify :

    suspend fun test(url: String): HttpResponse = coroutineScope {
        return@coroutineScope httpClient.get<HttpResponse>(url)
    }

But then I need to add the JSON parcelizer to all places this method is used.

I don’t follow, why is that?

Seems like this code works just fine:

suspend inline fun <reified T> getAsync(url: String) = coroutineScope {
    print(url)
    httpClient.get<T>(url)
}

This also works fine for me if I do coroutineScope.async with a val coroutineScope. Not sure which you intended based on code snippets and comments.

Do not use runBlocking from within a coroutine. It is a blocking call will block the dispatcher from running other coroutines.

Yeah, thanks, I tried to use coroutineScope.async or launch with my custom scope first:
val coroutineScope = CoroutineScope(job + Dispatchers.IO). With your example I also can’t set a dispatcher. Currently I don’t find a performance boost switching between coroutineScope and runBlocking - is it okay?