title: How to rewrite synchronous controller to be asynchronous in Play?
body: <p>I'm using Play framework 2.2 for one of my upcoming web application. I have implemented my controllers in synchronous pattern, with several blocking calls (mainly, database).</p>
  <p>For example,</p>
  <h3>Synchronous version:</h3>
  <pre><code>public static Result index(){
    User user = db.getUser(email); // blocking
    User anotherUser = db.getUser(emailTwo); // blocking
    ...
    user.sendEmail(); // call to a webservice, blocking.
    return ok();
  }
  </code></pre>
  <p>So, while optimising the code, decided to make use of Asynchronous programming support of Play. Gone through the documentation, but the idea is still vague to me, as I'm confused about how to properly convert the above synchronous block of code to Async.</p>
  <p>So, I came up with below code:</p>
  <h3>Asynchronous version:</h3>
  <pre><code>public static Promise&lt;Result&gt; index(){
    return Promise.promise(
      new Function0&lt;Result&gt;(){
        public Result apply(){
          User user = db.getUser(email); // blocking
          User anotherUser = db.getUser(emailTwo); // blocking
          ...
          user.sendEmail(); // call to a webservice, blocking.
          return ok();
        }
      }
    );
  }
  </code></pre>
  <p>So, I just wrapped the entire control logic inside a <code>promise</code> block.</p>
  <ol>
  <li>Is my approach correct?</li>
  <li>Should I convert each and every blocking request inside the controller, as Asynchronous, or wrapping several blocking calls inside single Async block is enough?</li>
  </ol>