in dekaf-main/src/pool/ServicePool.kt [102:117]
fun borrow(): S {
val t1 = now()
val tLimit = t1 + waitingTime
var h: Handle?
do {
if (shuttingDown) throw ShuttingDownException()
val sn = services.size
if ((deque.isEmpty() || sn < minServices) && sn < maxServices) {
h = askForNewService()
if (h != null) return h.activate()
}
h = deque.pollFirst(blockingTime, TimeUnit.MILLISECONDS)
if (h != null) return h.activate()
} while (now() < tLimit)
throw ExhaustedException()
}