blockingGet — do not call await if not pending

This commit is contained in:
Vladimir Krivosheev
2016-11-07 17:43:57 +01:00
parent 8fd99aaaa2
commit 0112cc26f0
@@ -182,10 +182,12 @@ open class AsyncPromise<T> : Promise<T>, Getter<T> {
}
override fun blockingGet(timeout: Int, timeUnit: TimeUnit): T? {
val latch = CountDownLatch(1)
processed { latch.countDown() }
if (!latch.await(timeout.toLong(), timeUnit)) {
throw TimeoutException()
if (isPending) {
val latch = CountDownLatch(1)
processed { latch.countDown() }
if (!latch.await(timeout.toLong(), timeUnit)) {
throw TimeoutException()
}
}
@Suppress("UNCHECKED_CAST")