title: What is the simplest way to timeout in Scala?
body: <p>There are many questions on SO that combine Futures with Timeout. To be honest, I haven't completely understood how to use them. But it seems I have stumbled upon a problem where I will have to (or maybe not).</p>
  
  <p>I want to throw a <code>TimeoutException</code> if a statement takes more than say 1 minute.To be more clear, currently, this statement tries to get a response from a server but does not throw if the server is not setup. It currently looks like this:</p>
  
  <pre><code>//proper import of exceptions
  case class ServerException(exception: Throwable) extends Exception(exception)
  //Code that instantiates client and post
  val response = try {
    client.execute(post)
  } catch {
    case e@(_: IOException | _: ClientProtocolException) =&gt; throw new ServerException(e)
  }
  </code></pre>
  
  <p>To mitigate this problem, I want to introduce a timeout. How do I introduce timeout to this statement such that it throws if no response is got within one minute, else it instantiates <code>response</code> and the program continues as it is?</p>