Skip to content

Instantly share code, notes, and snippets.

@beranradek
Last active December 17, 2015 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beranradek/5671908 to your computer and use it in GitHub Desktop.
Save beranradek/5671908 to your computer and use it in GitHub Desktop.
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