aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/scala/async/internal/FutureSystem.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/scala/async/internal/FutureSystem.scala')
-rw-r--r--src/main/scala/scala/async/internal/FutureSystem.scala13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/main/scala/scala/async/internal/FutureSystem.scala b/src/main/scala/scala/async/internal/FutureSystem.scala
index 6fccfdd..f330cbf 100644
--- a/src/main/scala/scala/async/internal/FutureSystem.scala
+++ b/src/main/scala/scala/async/internal/FutureSystem.scala
@@ -33,6 +33,7 @@ trait FutureSystem {
def promType[A: WeakTypeTag]: Type
def tryType[A: WeakTypeTag]: Type
def execContextType: Type
+ def stateMachineClassParents: List[Type] = Nil
/** Create an empty promise */
def createProm[A: WeakTypeTag]: Expr[Prom[A]]
@@ -48,13 +49,16 @@ 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")
/** Complete a promise with a value */
def completeProm[A](prom: Expr[Prom[A]], value: Expr[Tryy[A]]): Expr[Unit]
+ def completeWithSuccess[A: WeakTypeTag](prom: Expr[Prom[A]], value: Expr[A]): Expr[Unit] = completeProm(prom, tryySuccess(value))
def spawn(tree: Tree, execContext: Tree): Tree =
future(c.Expr[Unit](tree))(c.Expr[ExecContext](execContext)).tree
@@ -108,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 {