I am testing play framework 2.1 to check what happen when client cancel request or socket is closed from client side. I created this simple program:
package controllers;import play.; import play.mvc.;
import views.html.*;
public class Application extends Controller {
public static Result index() { try{ for(int i=0;i<1000;i++){ Thread.sleep(10000); System.out.println(i+"\n"); } }catch(Exception e){ System.out.println("\nexcepción capturada"); } return ok(index.render("Your new application is ready.")); }
}
If I cancel request from client (google chrome) the loop isn't aborted. I think this could be a problem in real world application, not making a loop, but doing a "heavy" query to database.
Since there was no answer I asked on the google group for play https://groups.google.com/forum/?hl=en#!topic/play-framework/POvFA3moXug and here is what James Roper from Typesafe said:
Play offers no such feature. However, there are other ways to achieve the same thing, for example, if you have a long running request, you could do it as a websockets request, which let's you easily detect when the client navigates to a different page.
The latest release as of today is play-2.2.0-RC1 (in case they add support later).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With