File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
src/library/scala/concurrent Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,9 @@ package object concurrent {
125
125
}
126
126
127
127
package concurrent {
128
+
129
+ import scala .util .Try
130
+
128
131
/**
129
132
* This marker trait is used by [[Await ]] to ensure that [[Awaitable.ready ]] and [[Awaitable.result ]]
130
133
* are not directly called by user code. An implicit instance of this trait is only available when
@@ -170,7 +173,7 @@ package concurrent {
170
173
@ throws(classOf [TimeoutException ])
171
174
@ throws(classOf [InterruptedException ])
172
175
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
174
177
case _ => blocking(awaitable.ready(atMost)(AwaitPermission ))
175
178
}
176
179
@@ -197,8 +200,12 @@ package concurrent {
197
200
@ throws(classOf [TimeoutException ])
198
201
@ throws(classOf [InterruptedException ])
199
202
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
201
204
case _ => blocking(awaitable.result(atMost)(AwaitPermission ))
202
205
}
206
+
207
+ private final object CompletedFuture {
208
+ def unapply [T ](f : Future [T ]): Option [Try [T ]] = f.value
209
+ }
203
210
}
204
211
}
You can’t perform that action at this time.
0 commit comments