Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fun main(args: Array<String>) {
val apiResult = runBlocking(Dispatchers.Default) {
val asyncResult = async { callApi() }
asyncResult.await()
}
println(apiResult)
}
fun callApi(): String {
val client = OkHttpClient()
val okRequest = Request.Builder()
.url("https://httpbin.org/get")
.build()
val responseResource: Response = client.newCall(okRequest).execute()
return responseResource.use {
responseResource.body?.string()!!
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment