@@ -23,6 +23,8 @@ trait FutureSystem {
2323 type Fut [A ]
2424 /** An execution context, required to create or register an on completion callback on a Future. */
2525 type ExecContext
26+ /** Any data type isomorphic to scala.util.Try. */
27+ type Tryy [T ]
2628
2729 trait Ops {
2830 val universe : reflect.internal.SymbolTable
@@ -31,6 +33,7 @@ trait FutureSystem {
3133 def Expr [T : WeakTypeTag ](tree : Tree ): Expr [T ] = universe.Expr [T ](rootMirror, universe.FixedMirrorTreeCreator (rootMirror, tree))
3234
3335 def promType [A : WeakTypeTag ]: Type
36+ def tryType [A : WeakTypeTag ]: Type
3437 def execContextType : Type
3538
3639 /** Create an empty promise */
@@ -43,15 +46,21 @@ trait FutureSystem {
4346 def future [A : WeakTypeTag ](a : Expr [A ])(execContext : Expr [ExecContext ]): Expr [Fut [A ]]
4447
4548 /** Register an call back to run on completion of the given future */
46- def onComplete [A , U ](future : Expr [Fut [A ]], fun : Expr [scala.util. Try [A ] => U ],
49+ def onComplete [A , U ](future : Expr [Fut [A ]], fun : Expr [Tryy [A ] => U ],
4750 execContext : Expr [ExecContext ]): Expr [Unit ]
4851
4952 /** Complete a promise with a value */
50- def completeProm [A ](prom : Expr [Prom [A ]], value : Expr [scala.util. Try [A ]]): Expr [Unit ]
53+ def completeProm [A ](prom : Expr [Prom [A ]], value : Expr [Tryy [A ]]): Expr [Unit ]
5154
5255 def spawn (tree : Tree , execContext : Tree ): Tree =
5356 future(Expr [Unit ](tree))(Expr [ExecContext ](execContext)).tree
5457
58+ def tryyIsFailure [A ](tryy : Expr [Tryy [A ]]): Expr [Boolean ]
59+
60+ def tryyGet [A ](tryy : Expr [Tryy [A ]]): Expr [A ]
61+ def tryySuccess [A : WeakTypeTag ](a : Expr [A ]): Expr [Tryy [A ]]
62+ def tryyFailure [A : WeakTypeTag ](a : Expr [Throwable ]): Expr [Tryy [A ]]
63+
5564 /** A hook for custom macros to transform the tree post-ANF transform */
5665 def postAnfTransform (tree : Block ): Block = tree
5766 }
@@ -66,13 +75,15 @@ object ScalaConcurrentFutureSystem extends FutureSystem {
6675 type Prom [A ] = Promise [A ]
6776 type Fut [A ] = Future [A ]
6877 type ExecContext = ExecutionContext
78+ type Tryy [A ] = scala.util.Try [A ]
6979
7080 def mkOps (c : SymbolTable ): Ops {val universe : c.type } = new Ops {
7181 val universe : c.type = c
7282
7383 import universe ._
7484
7585 def promType [A : WeakTypeTag ]: Type = weakTypeOf[Promise [A ]]
86+ def tryType [A : WeakTypeTag ]: Type = weakTypeOf[scala.util.Try [A ]]
7687 def execContextType : Type = weakTypeOf[ExecutionContext ]
7788
7889 def createProm [A : WeakTypeTag ]: Expr [Prom [A ]] = reify {
@@ -96,5 +107,19 @@ object ScalaConcurrentFutureSystem extends FutureSystem {
96107 prom.splice.complete(value.splice)
97108 Expr [Unit ](Literal (Constant (()))).splice
98109 }
110+
111+ def tryyIsFailure [A ](tryy : Expr [scala.util.Try [A ]]): Expr [Boolean ] = reify {
112+ tryy.splice.isFailure
113+ }
114+
115+ def tryyGet [A ](tryy : Expr [Tryy [A ]]): Expr [A ] = reify {
116+ tryy.splice.get
117+ }
118+ def tryySuccess [A : WeakTypeTag ](a : Expr [A ]): Expr [Tryy [A ]] = reify {
119+ scala.util.Success [A ](a.splice)
120+ }
121+ def tryyFailure [A : WeakTypeTag ](a : Expr [Throwable ]): Expr [Tryy [A ]] = reify {
122+ scala.util.Failure [A ](a.splice)
123+ }
99124 }
100125}
0 commit comments