<@U2E974ELT> so the bottom line is, your APIs has ...
# coroutines
s
@elizarov so the bottom line is, your APIs has to be non blocking all the way down in order to get the real advantage..rt? Does java HttpURLConnection qualify for a simple blocking API to use in examples? Eg: even though
makeRequest
is
a suspend
function, it blocks that common pool thread until it get a response.
Copy code
val jobs = (1..1000).map { n ->
    defer(CommonPool) {
        try {
            makeRequest(n)
        }catch (e : Exception) {
            Pair(n,e.message)
        }
    }
}

runBlocking {
    jobs.forEach {
        val r = it.await()
        println("Got response for ${r.first} - ${r.second}")
    }

}

suspend fun makeRequest(i : Int): Pair<Int, Int> {
   println("Creating request $i")
    val con = URL("<https://slack.com/>").openConnection() as HttpsURLConnection
    con.connectTimeout = 1000
    con.readTimeout = 1000
    con.instanceFollowRedirects = true
    con.requestMethod = "GET"
   // sleep(1000)
    return Pair(i, con.responseCode)
}