@@ -50,7 +50,13 @@ trait FutureSystem {
5050 execContext : Expr [ExecContext ]): Expr [Unit ]
5151
5252 /** Complete a promise with a value */
53- def completeProm [A ](prom : Expr [Prom [A ]], value : Expr [scala.util.Try [A ]]): Expr [Unit ]
53+ def completeProm [A : WeakTypeTag ](prom : Expr [Prom [A ]], value : Expr [A ]): Expr [Unit ]
54+
55+ /** Complete a promise with an exception */
56+ def completePromWithExceptionTopLevel [A : WeakTypeTag ](prom : Expr [Prom [A ]], exception : Expr [Throwable ]): Expr [Unit ]
57+
58+ /** Complete a promise with a failed result */
59+ def completePromWithFailedResult [A : WeakTypeTag ](prom : Expr [Prom [A ]], resultName : TermName ): Expr [Unit ]
5460
5561 def spawn (tree : context.Tree ): context.Tree =
5662 future(context.Expr [Unit ](tree))(execContext).tree
@@ -99,11 +105,26 @@ object ScalaConcurrentFutureSystem extends FutureSystem {
99105 future.splice.onComplete(fun.splice)(execContext.splice)
100106 }
101107
102- def completeProm [A ](prom : Expr [Prom [A ]], value : Expr [scala.util.Try [A ]]): Expr [Unit ] = reify {
103- prom.splice.complete(value.splice)
108+ def completeProm [A : WeakTypeTag ](prom : Expr [Prom [A ]], value : Expr [A ]): Expr [Unit ] = reify {
109+ prom.splice.success(value.splice)
110+ context.literalUnit.splice
111+ }
112+
113+ def completePromWithExceptionTopLevel [A : WeakTypeTag ](prom : Expr [Prom [A ]], exception : Expr [Throwable ]): Expr [Unit ] = reify {
114+ prom.splice.failure(exception.splice)
104115 context.literalUnit.splice
105116 }
106117
118+ def completePromWithFailedResult [A : WeakTypeTag ](prom : Expr [Prom [A ]], resultName : TermName ): Expr [Unit ] = {
119+ val result = c.Expr [scala.util.Try [A ]](
120+ TypeApply (Select (Ident (resultName), newTermName(" asInstanceOf" )),
121+ List (TypeTree (weakTypeOf[scala.util.Try [A ]]))))
122+ reify {
123+ prom.splice.complete(result.splice)
124+ context.literalUnit.splice
125+ }
126+ }
127+
107128 def castTo [A : WeakTypeTag ](future : Expr [Fut [Any ]]): Expr [Fut [A ]] = reify {
108129 future.splice.asInstanceOf [Fut [A ]]
109130 }
@@ -147,11 +168,24 @@ object IdentityFutureSystem extends FutureSystem {
147168 context.literalUnit.splice
148169 }
149170
150- def completeProm [A ](prom : Expr [Prom [A ]], value : Expr [scala.util. Try [ A ] ]): Expr [Unit ] = reify {
151- prom.splice.a = value.splice.get
171+ def completeProm [A : WeakTypeTag ](prom : Expr [Prom [A ]], value : Expr [A ]): Expr [Unit ] = reify {
172+ prom.splice.a = value.splice
152173 context.literalUnit.splice
153174 }
154175
176+ def completePromWithExceptionTopLevel [A : WeakTypeTag ](prom : Expr [Prom [A ]], exception : Expr [Throwable ]): Expr [Unit ] = reify {
177+ throw exception.splice
178+ }
179+
180+ def completePromWithFailedResult [A : WeakTypeTag ](prom : Expr [Prom [A ]], resultName : TermName ): Expr [Unit ] = {
181+ val result = c.Expr [scala.util.Try [A ]](
182+ TypeApply (Select (Ident (resultName), newTermName(" asInstanceOf" )),
183+ List (TypeTree (weakTypeOf[scala.util.Try [A ]]))))
184+ reify {
185+ throw result.splice.asInstanceOf [scala.util.Failure [A ]].exception
186+ }
187+ }
188+
155189 def castTo [A : WeakTypeTag ](future : Expr [Fut [Any ]]): Expr [Fut [A ]] = ???
156190 }
157191}
0 commit comments