added GUI_Thread.future (similar to JFX_GUI.Thread.future): useful for experimentation with Scala console in Isabelle/jEdit;
authorwenzelm
Mon, 04 Dec 2017 21:23:56 +0100
changeset 67129 0262a378d5d6
parent 67128 4d91b6d5d49c
child 67130 b023f64e0d16
added GUI_Thread.future (similar to JFX_GUI.Thread.future): useful for experimentation with Scala console in Isabelle/jEdit;
src/Pure/GUI/gui_thread.scala
--- a/src/Pure/GUI/gui_thread.scala	Mon Dec 04 18:30:28 2017 +0100
+++ b/src/Pure/GUI/gui_thread.scala	Mon Dec 04 21:23:56 2017 +0100
@@ -45,6 +45,16 @@
     else SwingUtilities.invokeLater(new Runnable { def run = body })
   }
 
+  def future[A](body: => A): Future[A] =
+  {
+    if (SwingUtilities.isEventDispatchThread()) Future.value(body)
+    else {
+      val promise = Future.promise[A]
+      later { promise.fulfill_result(Exn.capture(body)) }
+      promise
+    }
+  }
+
 
   /* delayed events */