title: Cancellation with Future and Promise in Scala
body: <p>This is a followup to <a href="https://stackoverflow.com/questions/16009837/how-to-cancel-future-in-scala">my previous question</a>. </p>
  
  <p>Suppose I have a task, which executes an <em>interruptible</em> blocking call. I would like to run it as a <code>Future</code> and <em>cancel</em> it with <code>failure</code> method of <code>Promise</code>.</p>
  
  <p>I would like the <em>cancel</em> to work as follows:</p>
  
  <ul>
  <li><p>If one <em>cancels</em> the task <em>before</em> it finished I would like the task to finish "immediately", interrupting the blocking call if it has already started and I would like the <code>Future</code> to invoke <code>onFailure</code>.</p></li>
  <li><p>If one <em>cancels</em> the task <em>after</em> the task finished I would like to get a status saying that the cancel failed since the task already finished. </p></li>
  </ul>
  
  <p>Does it make sense? Is it possible to implement in Scala? Are there any examples of such implementations?</p>