import kotlinx.coroutines.* import java.net.URL suspend fun test1() = coroutineScope { val url = "https://httpbin.org/get" val d1 = async(Dispatchers.IO) { URL(url).openStream().readBytes() } val d2 = async(Dispatchers.IO) { URL(url).openStream().readBytes() } println("d1=${d1.await().size}, d2=${d2.await().size}") } suspend fun loadUrl(url: String) = withContext(Dispatchers.IO) { URL(url).openStream().readBytes() } suspend fun test2() = coroutineScope { val url = "https://httpbin.org/get" val d1 = async { loadUrl(url) } val d2 = async { loadUrl(url) } println("d1=${d1.await().size}, d2=${d2.await().size}") } fun main() = runBlocking { GlobalScope.launch(Dispatchers.Default) { test1() test2() }.join() }