Package java8guide.async.controllers

Source Code of java8guide.async.controllers.Application

/*
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
*/
package java8guide.async.controllers;

import play.mvc.Result;
import play.libs.HttpExecution;
import play.libs.F.Promise;
import play.mvc.Controller;
import scala.concurrent.ExecutionContext;

public class Application extends Controller {
    //#async
    public Promise<Result> index() {
      return Promise.promise(() -> intensiveComputation())
                    .map((Integer i) -> ok("Got result: " + i));
    }
    //#async

    private ExecutionContext myThreadPool = null;

    //#async-explicit-ec
    public Promise<Result> index2() {
      // Wrap an existing thread pool, using the context from the current thread
      ExecutionContext myEc = HttpExecution.fromThread(myThreadPool);
      return Promise.promise(() -> intensiveComputation(), myEc)
                    .map((Integer i) -> ok("Got result: " + i), myEc);
    }
    //#async-explicit-ec

    public int intensiveComputation() { return 2;}
}
TOP

Related Classes of java8guide.async.controllers.Application

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.