Skip to content

Instantly share code, notes, and snippets.

@dacr
Created April 22, 2013 18:55
Show Gist options
  • Save dacr/5437528 to your computer and use it in GitHub Desktop.
Save dacr/5437528 to your computer and use it in GitHub Desktop.
Play : Get ride of Thread.sleep to simulate remote processing
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