src/Pure/System/swing_thread.scala
changeset 48000 880f1693299a
parent 47989 1e790c27162d
child 49195 9d10bd85c1be
--- a/src/Pure/System/swing_thread.scala	Fri May 25 11:18:32 2012 +0200
+++ b/src/Pure/System/swing_thread.scala	Fri May 25 13:19:10 2012 +0200
@@ -24,11 +24,12 @@
 
   def now[A](body: => A): A =
   {
-    @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)
+    if (SwingUtilities.isEventDispatchThread()) body
+    else {
+      lazy val result = { assert(); Exn.capture(body) }
+      SwingUtilities.invokeAndWait(new Runnable { def run = result })
+      Exn.release(result)
+    }
   }
 
   def future[A](body: => A): Future[A] =