more robust Swing_Thread.now: allow body to fail;
authorwenzelm
Thu, 24 May 2012 17:42:47 +0200
changeset 490041e790c27162d
parent 49003 e4b69e10b990
child 49005 7a642e5c272c
more robust Swing_Thread.now: allow body to fail;
src/Pure/System/swing_thread.scala
     1.1 --- a/src/Pure/System/swing_thread.scala	Thu May 24 17:25:53 2012 +0200
     1.2 +++ b/src/Pure/System/swing_thread.scala	Thu May 24 17:42:47 2012 +0200
     1.3 @@ -24,10 +24,11 @@
     1.4  
     1.5    def now[A](body: => A): A =
     1.6    {
     1.7 -    @volatile var result: Option[A] = None
     1.8 -    if (SwingUtilities.isEventDispatchThread()) { result = Some(body) }
     1.9 -    else SwingUtilities.invokeAndWait(new Runnable { def run = { result = Some(body) } })
    1.10 -    result.get
    1.11 +    @volatile var result: Option[Exn.Result[A]] = None
    1.12 +    if (SwingUtilities.isEventDispatchThread()) { result = Some(Exn.capture(body)) }
    1.13 +    else
    1.14 +      SwingUtilities.invokeAndWait(new Runnable { def run = { result = Some(Exn.capture(body)) } })
    1.15 +    Exn.release(result.get)
    1.16    }
    1.17  
    1.18    def future[A](body: => A): Future[A] =