Skip to content

Commit 0193038

Browse files
authored
Merge pull request scala/scala#8795 from som-snytt/issue/11903
[backport] 7768 completed future is not blocking
2 parents 451f0d7 + 272be1e commit 0193038

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

library/src/scala/concurrent/package.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ package concurrent {
191191
*/
192192
@throws(classOf[TimeoutException])
193193
@throws(classOf[InterruptedException])
194-
def ready[T](awaitable: Awaitable[T], atMost: Duration): awaitable.type =
195-
blocking(awaitable.ready(atMost)(AwaitPermission))
194+
def ready[T](awaitable: Awaitable[T], atMost: Duration): awaitable.type = awaitable match {
195+
case f: Future[T] if f.isCompleted => awaitable.ready(atMost)(AwaitPermission)
196+
case _ => blocking(awaitable.ready(atMost)(AwaitPermission))
197+
}
196198

197199
/**
198200
* Await and return the result (of type `T`) of an `Awaitable`.
@@ -216,7 +218,9 @@ package concurrent {
216218
*/
217219
@throws(classOf[TimeoutException])
218220
@throws(classOf[InterruptedException])
219-
def result[T](awaitable: Awaitable[T], atMost: Duration): T =
220-
blocking(awaitable.result(atMost)(AwaitPermission))
221+
def result[T](awaitable: Awaitable[T], atMost: Duration): T = awaitable match {
222+
case f: Future[_] if f.isCompleted => awaitable.result(atMost)(AwaitPermission)
223+
case _ => blocking(awaitable.result(atMost)(AwaitPermission))
224+
}
221225
}
222226
}

0 commit comments

Comments
 (0)