title: Play 2.2.1 -Making async call in Filter
body: <p>I'm storing a token in redis and using the <a href="https://github.com/debasishg/scala-redis-nb" rel="nofollow">redis non-blocking lib</a> to fetch it .   This library returns a Future[Option[String]] for the get api call that I am using. I can't figure out how to handle this in the flow while keeping it async.  I can get it working if I  introduce a blocking call using Await.result like so -</p>
  
  <pre><code>object TokenFilter extends Filter {
    def apply(nextFilter: (RequestHeader) =&gt; Future[SimpleResult])
             (requestHeader: RequestHeader): Future[SimpleResult] = {    
      import scala.concurrent.ExecutionContext.Implicits.global     
      implicit val system = ActorSystem("redis-Client")
      implicit val executionContext = system.dispatcher
      implicit val timeout = AkkaTimeout(2 seconds)
  
      val accesstoken: Future[Option[String]] = RedisClientFactory.getRedisClient().get("key11")
  
      val result = Await.result(accesstoken, 2 second)
      result match {
        case Some(v) =&gt;
          Logger.info("success with value " + v)
          nextFilter(requestHeader)
        case None =&gt;
            Logger.info("failure with None ")
            Future.successful(Results.Forbidden)        
     }
  
    }       
  }
  </code></pre>
  
  <p>I seem to be missing some basic concept here. Any pointers will be greatly appreciated. I need to call nextFilter(requestHeader) for success else return Results.Forbidden.</p>
  
  <p>Here is some of my attempt that doesn't type check.</p>
  
  <pre><code>    accesstoken map{ result =&gt;
        result match {
            case Some(v) =&gt;
              Logger.info("success with value " + v)
              nextFilter(requestHeader)   //won't type check
            case None =&gt;
                Logger.info("failure with None ")
                Results.Forbidden
            }
      }
  </code></pre>