Last active
December 17, 2015 20:59
-
-
Save beranradek/5671908 to your computer and use it in GitHub Desktop.
This file contains 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.api.mvc.Action | |
import play.api.mvc.Controller | |
import scala.concurrent.future | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import play.api.Logger | |
object Performance extends Controller { | |
def sync(durationMs: Long) = Action { | |
operation(durationMs) | |
Logger.info("Sync taking " + durationMs + | |
" ms at " + System.currentTimeMillis()) | |
Ok("sync done") | |
} | |
def async(durationMs: Long) = Action { | |
val futureResult = future { | |
operation(durationMs) | |
} | |
Async { | |
futureResult.map { | |
Logger.info("Async taking " + durationMs + | |
" ms at " + System.currentTimeMillis()) | |
(u: Unit) => Ok("async done") | |
} | |
} | |
} | |
def operation(durationMs: Long) = { | |
Thread.sleep(durationMs) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment