diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2016-03-03 14:35:46 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2016-03-03 14:35:46 +1000 |
commit | d03f34c3e16dc7a6ddb6a3efa4fca5ee3f989c85 (patch) | |
tree | e63defea9ab4f85ddc79bfc75a89205191c5376a /src/main/scala/scala/async/internal/FutureSystem.scala | |
parent | 4395afe0ab7c59f088607d0849abe48b0f83265d (diff) | |
download | scala-async-d03f34c3e16dc7a6ddb6a3efa4fca5ee3f989c85.tar.gz scala-async-d03f34c3e16dc7a6ddb6a3efa4fca5ee3f989c85.tar.bz2 scala-async-d03f34c3e16dc7a6ddb6a3efa4fca5ee3f989c85.zip |
Rework extension point for checking for already-completed futures
The current extension point assumes that if a future is in the
completed state, a subsequent call to get the already completed
value will succeed. While this assumption holds for
scala.concurrent.Future, it might not hold for a future system
that has semantics like a weak reference.
This commit uses a single call `getCompleted` to query the state
and get the already completed value. This returns null if the
value is not available.
Diffstat (limited to 'src/main/scala/scala/async/internal/FutureSystem.scala')
-rw-r--r-- | src/main/scala/scala/async/internal/FutureSystem.scala | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/main/scala/scala/async/internal/FutureSystem.scala b/src/main/scala/scala/async/internal/FutureSystem.scala index 04adafc..f330cbf 100644 --- a/src/main/scala/scala/async/internal/FutureSystem.scala +++ b/src/main/scala/scala/async/internal/FutureSystem.scala @@ -49,8 +49,10 @@ trait FutureSystem { execContext: Expr[ExecContext]): Expr[Unit] def continueCompletedFutureOnSameThread = false - def isCompleted(future: Expr[Fut[_]]): Expr[Boolean] = - throw new UnsupportedOperationException("isCompleted not supported by this FutureSystem") + + /** Return `null` if this future is not yet completed, or `Tryy[A]` with the completed result + * otherwise + */ def getCompleted[A: WeakTypeTag](future: Expr[Fut[A]]): Expr[Tryy[A]] = throw new UnsupportedOperationException("getCompleted not supported by this FutureSystem") @@ -110,11 +112,8 @@ object ScalaConcurrentFutureSystem extends FutureSystem { override def continueCompletedFutureOnSameThread: Boolean = true - override def isCompleted(future: Expr[Fut[_]]): Expr[Boolean] = reify { - future.splice.isCompleted - } override def getCompleted[A: WeakTypeTag](future: Expr[Fut[A]]): Expr[Tryy[A]] = reify { - future.splice.value.get + if (future.splice.isCompleted) future.splice.value.get else null } def completeProm[A](prom: Expr[Prom[A]], value: Expr[scala.util.Try[A]]): Expr[Unit] = reify { |