Skip to content

Instantly share code, notes, and snippets.

@guillaumebort
Created May 16, 2012 16:23
Show Gist options
  • Save guillaumebort/2711847 to your computer and use it in GitHub Desktop.
Save guillaumebort/2711847 to your computer and use it in GitHub Desktop.
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