I need to call into a service that may or not return timely results. I\'d like to be able to write
val result = runWithTimeout(5000, valReturnedOnTimeout) {         
        
The post above
  import scala.concurrent.ExecutionContext.Implicits.global   import
 scala.concurrent._   import scala.concurrent.duration._
   def runWithTimeout[T](timeoutMs: Long)(f: => T) : Option[T] = {
     Await.result(Future(f), timeoutMs milliseconds).asInstanceOf[Option[T]]   }
   def runWithTimeout[T](timeoutMs: Long, default: T)(f: => T) : T = {
     runWithTimeout(timeoutMs)(f).getOrElse(default)   }
didn't work for me on Scala 2.11.
Following modified version works for me:
  def runWithTimeout[T](timeout: Long)(f: => T): Option[T] = {
    Option.apply(Await.result(Future(f), timeout seconds))
  }