Package playn.core
Class Exec
java.lang.Object
playn.core.Exec
- Direct Known Subclasses:
Exec.Default
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)
).-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A default exec implementation which processesExec.Default.invokeLater(java.lang.Runnable)
via the frame tick. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<T> RPromise<T>
Creates a promise which defers notification of success or failure to the game thread, regardless of what thread on which it is completed.void
invokeAsync
(Runnable action) Invokes the supplied action on a separate thread.abstract void
invokeLater
(Runnable action) Invokesaction
on the nextPlatform.frame
signal or, if the game is paused, on the OS UI thread.abstract void
invokeNextFrame
(Runnable action) Invokesaction
on the nextPlatform.frame
signal.boolean
Returns whether this platform supports async (background) operations.abstract boolean
Returns true if the caller is running on the 'main' game thread, false otherwise.
-
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
Invokesaction
on the nextPlatform.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
Invokesaction
on the nextPlatform.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 (likeinvokeNextFrame(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 useinvokeLater
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
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
Invokes the supplied action on a separate thread.- Throws:
UnsupportedOperationException
- if the platform does not support async operations.
-