Created
May 16, 2012 16:23
-
-
Save guillaumebort/2711847 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers; | |
import play.*; | |
import play.mvc.*; | |
import play.libs.F.*; | |
import views.html.*; | |
public class Application extends Controller { | |
public static Result index() { | |
// This promise will be redeemed after that the response is sent back to the client | |
Promise.timeout("Bouh", 10000l).onRedeem(new Callback<String>() { | |
public void invoke(String s) { | |
System.out.println("YEP " + s + " with request -> " + request()); | |
} | |
}); | |
return async( | |
Promise.timeout("Hello...", 1000l) | |
.flatMap(new Function<String,Promise<String>>() { | |
public Promise<String> apply(final String s1) { | |
return Promise.timeout("kiki", 1000l) | |
.map(new Function<String,String>() { | |
public String apply(final String s2) { | |
return s1 + " " + s2; | |
} | |
}); | |
} | |
}) | |
.map(new Function<String,Result>() { | |
public Result apply(String s) { | |
return ok(s + " !!!! " + request()); | |
} | |
}) | |
.recover(new Function<Throwable,Result>() { | |
public Result apply(Throwable t) { | |
return internalServerError("OOPS -> " + t); | |
} | |
}) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment