added Promise.cancel;
authorwenzelm
Wed, 14 Jan 2015 16:23:33 +0100
changeset 59365 b5d43b01a6b3
parent 59364 3b5da177ae6b
child 59366 e94df7f6b608
added Promise.cancel;
src/Pure/Concurrent/future.scala
--- a/src/Pure/Concurrent/future.scala	Wed Jan 14 14:28:52 2015 +0100
+++ b/src/Pure/Concurrent/future.scala	Wed Jan 14 16:23:33 2015 +0100
@@ -47,6 +47,7 @@
 
 trait Promise[A] extends Future[A]
 {
+  def cancel: Unit
   def fulfill_result(res: Exn.Result[A]): Unit
   def fulfill(x: A): Unit
 }
@@ -78,6 +79,10 @@
 {
   override def is_finished: Boolean = promise.isCompleted
 
+  def cancel: Unit =
+    try { fulfill_result(Exn.Exn(Exn.Interrupt())) }
+    catch { case _: IllegalStateException => }
+
   def fulfill_result(res: Exn.Result[A]): Unit =
     res match {
       case Exn.Res(x) => promise.success(x)