more robust Swing_Thread.now: allow body to fail;
authorwenzelm
Thu, 24 May 2012 17:42:47 +0200
changeset 47989 1e790c27162d
parent 47988 e4b69e10b990
child 47990 7a642e5c272c
more robust Swing_Thread.now: allow body to fail;
src/Pure/System/swing_thread.scala
--- a/src/Pure/System/swing_thread.scala	Thu May 24 17:25:53 2012 +0200
+++ b/src/Pure/System/swing_thread.scala	Thu May 24 17:42:47 2012 +0200
@@ -24,10 +24,11 @@
 
   def now[A](body: => A): A =
   {
-    @volatile var result: Option[A] = None
-    if (SwingUtilities.isEventDispatchThread()) { result = Some(body) }
-    else SwingUtilities.invokeAndWait(new Runnable { def run = { result = Some(body) } })
-    result.get
+    @volatile var result: Option[Exn.Result[A]] = None
+    if (SwingUtilities.isEventDispatchThread()) { result = Some(Exn.capture(body)) }
+    else
+      SwingUtilities.invokeAndWait(new Runnable { def run = { result = Some(Exn.capture(body)) } })
+    Exn.release(result.get)
   }
 
   def future[A](body: => A): Future[A] =