src/Pure/System/jfx_thread.scala
author wenzelm
Tue, 12 Mar 2013 16:47:24 +0100
changeset 51399 6ac3c29a300e
parent 49066 1067a639d42a
permissions -rw-r--r--
discontinued "isabelle usedir" option -r (reset session path); simplified internal session identification: chapter / name; clarified chapter index (of sessions) vs. session index (of theories); discontinued "up" links, for improved modularity also wrt. partial browser_info (users can use "back" within the browser); removed obsolete session parent_path;

/*  Title:      Pure/System/jfx_thread.scala
    Module:     PIDE
    Author:     Makarius

Evaluation within the Java FX application thread.
*/

package isabelle

import javafx.application.{Platform => JFX_Platform}


object JFX_Thread
{
  /* checks */

  def assert() = Predef.assert(JFX_Platform.isFxApplicationThread())
  def require() = Predef.require(JFX_Platform.isFxApplicationThread())


  /* asynchronous context switch */

  def later(body: => Unit)
  {
    if (JFX_Platform.isFxApplicationThread()) body
    else JFX_Platform.runLater(new Runnable { def run = body })
  }

  def future[A](body: => A): Future[A] =
  {
    if (JFX_Platform.isFxApplicationThread()) Future.value(body)
    else {
      val promise = Future.promise[A]
      later { promise.fulfill_result(Exn.capture(body)) }
      promise
    }
  }
}