Browse Source

Returning a thunk for failure in order to defer the evaluation of it.

Christopher Hunt 12 years ago
parent
commit
59b55bd7c2

+ 1 - 1
play-scala/app/controllers/Application.scala

@@ -40,7 +40,7 @@ object Application extends Controller {
     Ok(Json.obj("message" -> "Hello World!"))
   }
 
-  def db(queries: Int) = PredicatedAction(isDbAvailable, Results.ServiceUnavailable) {
+  def db(queries: Int) = PredicatedAction(isDbAvailable, ServiceUnavailable) {
     Action {
       Async {
         val random = ThreadLocalRandom.current()

+ 1 - 2
play-scala/app/utils/PredicatedAction.scala

@@ -1,14 +1,13 @@
 package utils
 
 import play.api.mvc._
-import play.api.http.Status
 
 /**
  * A predicated action is one where a condition must be satisfied in order to proceed with the request. If the
  * condition is not satisfied then a supplied status result is yielded.
  */
 class PredicatedActionBuilder {
-  def apply[A](p: => Boolean, failed: Results.Status)(action: Action[A]): Action[A] = new Action[A] {
+  def apply[A](p: => Boolean, failed: => Result)(action: Action[A]): Action[A] = new Action[A] {
     def apply(request: Request[A]): Result = {
       if (p) action(request) else failed
     }