diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-12-15 17:34:51 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-12-16 11:05:22 +1000 |
commit | 063492a14a004cb519f553a6cd30f8b3e41f0453 (patch) | |
tree | 19413879ab94f946c0456e97a660fb86f179a5a8 /src/main/scala/scala/async/internal/FutureSystem.scala | |
parent | c0d711570b76fb17f8f58a80f8529dcb9cbfdb2c (diff) | |
download | scala-async-063492a14a004cb519f553a6cd30f8b3e41f0453.tar.gz scala-async-063492a14a004cb519f553a6cd30f8b3e41f0453.tar.bz2 scala-async-063492a14a004cb519f553a6cd30f8b3e41f0453.zip |
Make `f(await(completedFuture))` execute `f` synchronously
A worthy optimization, suggested by @danarmak.
Closes #73
Diffstat (limited to 'src/main/scala/scala/async/internal/FutureSystem.scala')
-rw-r--r-- | src/main/scala/scala/async/internal/FutureSystem.scala | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/main/scala/scala/async/internal/FutureSystem.scala b/src/main/scala/scala/async/internal/FutureSystem.scala index 46c0bcf..96356ed 100644 --- a/src/main/scala/scala/async/internal/FutureSystem.scala +++ b/src/main/scala/scala/async/internal/FutureSystem.scala @@ -49,6 +49,12 @@ trait FutureSystem { def onComplete[A, U](future: Expr[Fut[A]], fun: Expr[Tryy[A] => U], execContext: Expr[ExecContext]): Expr[Unit] + def continueCompletedFutureOnSameThread = false + def isCompleted(future: Expr[Fut[_]]): Expr[Boolean] = + throw new UnsupportedOperationException("isCompleted not supported by this FutureSystem") + def getCompleted[A: WeakTypeTag](future: Expr[Fut[A]]): Expr[Tryy[A]] = + throw new UnsupportedOperationException("getCompleted not supported by this FutureSystem") + /** Complete a promise with a value */ def completeProm[A](prom: Expr[Prom[A]], value: Expr[Tryy[A]]): Expr[Unit] @@ -103,6 +109,15 @@ object ScalaConcurrentFutureSystem extends FutureSystem { future.splice.onComplete(fun.splice)(execContext.splice) } + 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 + } + def completeProm[A](prom: Expr[Prom[A]], value: Expr[scala.util.Try[A]]): Expr[Unit] = reify { prom.splice.complete(value.splice) Expr[Unit](Literal(Constant(()))).splice |