blockingGet — do not call await if not pending
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Mon, 7 Nov 2016 16:39:07 +0000 (17:39 +0100)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Mon, 7 Nov 2016 16:43:57 +0000 (17:43 +0100)
platform/projectModel-api/src/org/jetbrains/concurrency/AsyncPromise.kt

index a32c4f8ed4b81794e8f3305fdb79c82902479601..b6312da03294db82d07a9693b9229b34938a4388 100644 (file)
@@ -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")