Permalink
Browse files

[#966] Retrieve renderArgs when using F.Action callback for await

  • Loading branch information...
1 parent f94a3fc commit d9b156afd37009d47b2334e27915cc094f65140b @revbingo revbingo committed Jul 10, 2011
@@ -27,6 +27,7 @@
import play.exceptions.PlayException;
import play.exceptions.UnexpectedException;
import play.i18n.Lang;
+import play.mvc.Http.Request;
import play.mvc.Router.Route;
import play.mvc.results.NoResult;
import play.mvc.results.Result;
@@ -516,6 +517,8 @@ static Object invokeWithContinuation(Method method, Object instance, Object[] re
// Action0
instance = Http.Request.current().args.get(A);
Future f = (Future) Http.Request.current().args.get(F);
+ Scope.RenderArgs renderArgs = (Scope.RenderArgs) Request.current().args.remove(ActionInvoker.CONTINUATIONS_STORE_RENDER_ARGS);
+ Scope.RenderArgs.current.set(renderArgs);
if (f == null) {
method = instance.getClass().getDeclaredMethod("invoke");
method.setAccessible(true);
@@ -955,6 +955,7 @@ private static void storeOrRestoreDataStateForContinuations(Boolean isRestoring)
protected static void await(int millis, F.Action0 callback) {
Request.current().isNew = false;
Request.current().args.put(ActionInvoker.A, callback);
+ storeOrRestoreDataStateForContinuations(null);
throw new Suspend(millis);
}
@@ -1036,6 +1037,7 @@ private static void verifyContinuationsEnhancement() {
Request.current().isNew = false;
Request.current().args.put(ActionInvoker.F, future);
Request.current().args.put(ActionInvoker.A, callback);
+ storeOrRestoreDataStateForContinuations(null);
throw new Suspend(future);
}
@@ -391,5 +391,35 @@ public String doJobWithResult() {
renderText( res );
}
+ public static void usingRenderArgsAndAwaitWithCallBack(String arg) {
+ renderArgs.put("arg", arg);
+
+ await("1s", new F.Action0() {
+
+ @Override
+ public void invoke() {
+ renderText(renderArgs.get("arg"));
+ }
+ });
+ }
+
+ public static void usingRenderArgsAndAwaitWithFutureAndCallback(final String arg) {
+ renderArgs.put("arg", arg);
+
+ Promise<String> promise = new Job() {
+ @Override
+ public String doJobWithResult() throws Exception {
+ return "result";
+ }
+
+ }.now();
+ await(promise, new F.Action<String>() {
+
+ @Override
+ public void invoke(String result) {
+ renderText(result + "/" + renderArgs.get("arg"));
+ }
+ });
+ }
}
@@ -98,5 +98,10 @@
open('@{WithContinuations.usingRenderArgsAndAwait()}')
assertBodyText('true')
+ open('@{WithContinuations.usingRenderArgsAndAwaitWithCallBack("renderArg")}')
+ assertBodyText('renderArg')
+
+ open('@{WithContinuations.usingRenderArgsAndAwaitWithFutureAndCallback("renderArg")}')
+ assertBodyText('result/renderArg')
#{/selenium}

0 comments on commit d9b156a

Please sign in to comment.