Content-Length: 293842 | pFad | http://github.com/scala/scala/commit/fbd326dc19fb825355d037a11834f8631734ad4f

71 perf: avoid double checking `value0` Future. · scala/scala@fbd326d · GitHub
Skip to content

Commit fbd326d

Browse files
committed
perf: avoid double checking value0 Future.
1 parent 360d5da commit fbd326d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/library/scala/concurrent/package.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ package object concurrent {
125125
}
126126

127127
package concurrent {
128+
129+
import scala.util.Try
130+
128131
/**
129132
* This marker trait is used by [[Await]] to ensure that [[Awaitable.ready]] and [[Awaitable.result]]
130133
* are not directly called by user code. An implicit instance of this trait is only available when
@@ -170,7 +173,7 @@ package concurrent {
170173
@throws(classOf[TimeoutException])
171174
@throws(classOf[InterruptedException])
172175
final def ready[T](awaitable: Awaitable[T], atMost: Duration): awaitable.type = awaitable match {
173-
case f: Future[T] if f.isCompleted => awaitable.ready(atMost)(AwaitPermission)
176+
case f: Future[T] if f.isCompleted => awaitable
174177
case _ => blocking(awaitable.ready(atMost)(AwaitPermission))
175178
}
176179

@@ -197,8 +200,12 @@ package concurrent {
197200
@throws(classOf[TimeoutException])
198201
@throws(classOf[InterruptedException])
199202
final def result[T](awaitable: Awaitable[T], atMost: Duration): T = awaitable match {
200-
case f: Future[T] if f.isCompleted => f.result(atMost)(AwaitPermission)
203+
case CompletedFuture(result) => result.get
201204
case _ => blocking(awaitable.result(atMost)(AwaitPermission))
202205
}
206+
207+
private final object CompletedFuture {
208+
def unapply[T](f: Future[T]): Option[Try[T]] = f.value
209+
}
203210
}
204211
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/scala/scala/commit/fbd326dc19fb825355d037a11834f8631734ad4f

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy