Josep Rovira
08/13/2023, 9:53 AMval result = runBlocking(this.coroutineContext.newCoroutineContext(<http://Dispatchers.IO|Dispatchers.IO>)) {
    val resultOne = async { 
        ...
    }
    val resultTwo = async { 
        ...
    }
    return@runBlocking Pair(resultOne.await(), resultTwo.await())
}
But it seems it always blocks other requests and the server stops responding when handling lots of parallel requests.
Any help is appreciated, thanks!!Chrimaeon
08/13/2023, 11:21 AMJosep Rovira
08/13/2023, 2:51 PMval result = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
    val resultOne = async { 
        ...
    }
    val resultTwo = async { 
        ...
    }
    return@withContext Pair(resultOne.await(), resultTwo.await())
}
runBlocking is not needed since it's already in Ktor's coroutine  (I think)Patrick Steiger
08/13/2023, 3:16 PMcoroutineScope {} or supervisorScope {}. withContext is to be used when you want to change contextAleksei Tirman [JB]
08/13/2023, 6:34 PMembeddedServer(Netty, host = "localhost", port = 9090) {
    routing {
        get {
            val tasks = mutableListOf<Deferred<*>>()
            tasks.add(async {
                delay(500)
                println("task1")
            })
            tasks.add(async {
                delay(1000)
                println("task2")
            })
            tasks.awaitAll()
            call.respondText { "OK" }
        }
    }
}.start(wait = true)