Created
April 22, 2013 18:55
-
-
Save dacr/5437528 to your computer and use it in GitHub Desktop.
Play : Get ride of Thread.sleep to simulate remote processing
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._ | |
import play.api.mvc._ | |
import play.api.libs.concurrent.Execution.Implicits._ | |
import play.api.libs.concurrent.Akka | |
import play.api.Play.current | |
import scala.concurrent._ | |
import scala.concurrent.duration._ | |
object Dummy extends Controller { | |
// ------------------------------------------------------------ | |
def slowtest(delayInSeconds:Int) = Action { | |
val thepromise = Promise[String]() | |
Akka.system.scheduler.scheduleOnce(delayInSeconds seconds) { | |
thepromise success s"I'm slow, $delayInSeconds seconds" | |
} | |
Async { | |
thepromise.future map { msg=> Ok(views.html.message(msg)) } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment