Package playn.core

Class Exec

java.lang.Object
playn.core.Exec
Direct Known Subclasses:
Exec.Default

public abstract class Exec extends Object
Handles execution of units of code, both on background threads (invokeAsync(java.lang.Runnable)) and on the main PlayN game thread (invokeLater(java.lang.Runnable)).
  • Constructor Details

    • Exec

      public Exec()
  • Method Details

    • isMainThread

      public abstract boolean isMainThread()
      Returns true if the caller is running on the 'main' game thread, false otherwise.
    • invokeNextFrame

      public abstract void invokeNextFrame(Runnable action)
      Invokes action on the next Platform.frame signal. The default implementation listens to the frame signal at a very high priority so that invoke later actions will run before the game's normal callbacks. Note: if the game is paused, these actions will not run until it is unpaused and the next game frame is processed.
    • invokeLater

      public abstract void invokeLater(Runnable action)
      Invokes action on the next Platform.frame signal or, if the game is paused, on the OS UI thread. Actions posted here will still be run in order and in a single threaded manner (like invokeNextFrame(java.lang.Runnable)), but they are not guaranteed to run on the game thread if the game is paused during the frame on which actions are posted.

      If you're deferring a graphics or (game) UI action, you should almost certainly use invokeNextFrame(java.lang.Runnable), but if you are deferring an action like saving data or initiating a network connection, you may wish to use invokeLater to ensure that those actions are completed even if the player happens to pause the game (by backgrounding the app on mobile, for example) immediately after they are queued up.

    • deferredPromise

      public <T> RPromise<T> deferredPromise()
      Creates a promise which defers notification of success or failure to the game thread, regardless of what thread on which it is completed. Note that even if it is completed on the game thread, it will still defer completion until the next frame.
    • isAsyncSupported

      public boolean isAsyncSupported()
      Returns whether this platform supports async (background) operations. HTML doesn't, most other platforms do.
    • invokeAsync

      public void invokeAsync(Runnable action)
      Invokes the supplied action on a separate thread.
      Throws:
      UnsupportedOperationException - if the platform does not support async operations.