Skip to content

Instantly share code, notes, and snippets.

@yschimke
Created November 28, 2021 10:01
Show Gist options
  • Save yschimke/3132e0a059e4d74f99c1f7321a26b4a4 to your computer and use it in GitHub Desktop.
Save yschimke/3132e0a059e4d74f99c1f7321a26b4a4 to your computer and use it in GitHub Desktop.
package okhttp3
import java.io.IOException
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
fun main() {
val client = OkHttpClient.Builder()
.pingInterval(2500, TimeUnit.MILLISECONDS)
.connectionPool(ConnectionPool(0, 1, TimeUnit.NANOSECONDS))
.build()
val latch = CountDownLatch(1)
val request = Request.Builder().url("https://nghttp2.org/httpbin/get").build()
client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
println("onFailure")
latch.countDown()
}
override fun onResponse(call: Call, response: Response) {
println("onResponse")
// println(response.body?.string())
println(response.protocol)
// response.close()
latch.countDown()
}
})
println("await")
latch.await()
println("awaited")
println(client.connectionPool.connectionCount())
// client.connectionPool.evictAll()
// println(client.connectionPool.connectionCount())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment