java.lang.Object
com.iamsoft.util.ui.javafx.TaskUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
callOnJavaFxThread
(Supplier<T> pCallable) static <S,
T> void mapOnJavaFxThread
(Stream<S> pStream, Function<S, T> pMapper, int pMaxStepDuration, Consumer<T> pConsumer) This method blocks until all elements are processed.static void
onFinished
(List<? extends javafx.concurrent.Task<?>> pTasks, Runnable pRunnable) Runs the specified runnable when all of the specified tasks are cancelled or finished (successfully or not).static <T> T
runAndWait
(Callable<T> pCallable) Invokes the specified supplier on a background thread and waits without blocking UI.static <T> T
runAndWait
(Callable<T> pCallable, long pTimeoutMillis) Invokes the specified supplier on a background thread and waits without blocking UI.static <T> T
runAndWait
(Callable<T> pCallable, long pTimeoutMillis, javafx.scene.Scene pScene) Invokes the specified supplier on a background thread and waits without blocking UI.static <T> T
runAndWait
(Callable<T> pCallable, Consumer<Runnable> pExecutor) This method must either be called from an input event handler or from the run method of a Runnable passed toPlatform.runLater
.static <T> T
runAndWait
(Callable<T> pCallable, Consumer<Runnable> pExecutor, long pTimeoutMillis, javafx.scene.Scene pScene) Invokes the specified supplier on a background thread and waits without blocking UI.static <T> T
runAndWait
(Callable<T> pCallable, Consumer<Runnable> pExecutor, Runnable pInterruptOp, long pTimeoutMillis) This method must either be called from an input event handler or from the run method of a Runnable passed toPlatform.runLater
.static void
This method can be used to run later a lot of runnables without flooding the event queue.static void
This method can be used to run later a lot of runnables on steps.static void
runOnceLater
(Runnable pRunnable) This method can be used to run a runnable only once per run later event.static void
runOnJavaFxThreadAndWait
(Runnable pRunnable) static <T> void
supplyLater
(Supplier<T> pSupplier, Consumer<List<T>> pConsumer, int pItemsPerStep, double pMinDuration) Can be invoked on a background thread to supply (on the JavaFX thread) items to the specified consumer on portions.static <T> void
supplyLater
(Stream<T> pItemStream, Consumer<List<T>> pConsumer, int pItemsPerStep, double pMinDuration) Can be invoked on a background thread to supply (on the JavaFX thread) items to the specified consumer on portions.static void
waitForCallbackEvent
(Consumer<Runnable> pFunction) There are functions which notify about an event, asynchronously, through a callback specified as a parameter.static boolean
waitForCallbackEvent
(Consumer<Runnable> pFunction, long pTimeoutMillis, javafx.scene.Scene pScene) There are functions which notify about an event, asynchronously, through a callback specified as a parameter.static <T> T
waitForCallbackResult
(Consumer<Consumer<T>> pFunction) There are functions which notify about an event, asynchronously, through a callback specified as a parameter.static <T> T
waitForCallbackResult
(Consumer<Consumer<T>> pFunction, long pTimeoutMillis, javafx.scene.Scene pScene) There are functions which notify about an event, asynchronously, through a callback specified as a parameter.
-
Method Details
-
onFinished
Runs the specified runnable when all of the specified tasks are cancelled or finished (successfully or not). -
runLater
This method can be used to run later a lot of runnables without flooding the event queue. Note that Platform.runLater(Runnable) is not a cheap operation. -
runLater
This method can be used to run later a lot of runnables on steps.- Parameters:
pRunnable
- A non-null runnable to execute on the JavaFX thread.pMinStepDuration
- If there are enough runnables to run, specifies a minimum duration of how long the JavaFX thread should be blocked to run runnables before releasing the JavaFX thread and move to next step by running later again. Note that if there are previous runnables, which are not run yet, this argument will be ignored in favor of minimum step duration specified in previous call of this method.
-
runOnceLater
This method can be used to run a runnable only once per run later event. Meaning that multiple invocations of this method for same runnable, happening before a run-later event occurs, will be ignored. -
runAndWait
Invokes the specified supplier on a background thread and waits without blocking UI. This method must either be called from an input event handler or from the run method of a Runnable passed toPlatform.runLater
. It must not be called during animation or layout processing. -
runAndWait
public static <T> T runAndWait(Callable<T> pCallable, long pTimeoutMillis, javafx.scene.Scene pScene) Invokes the specified supplier on a background thread and waits without blocking UI. This method must either be called from an input event handler or from the run method of a Runnable passed toPlatform.runLater
. It must not be called during animation or layout processing.- Parameters:
pTimeoutMillis
- Duration in milliseconds to wait before giving up. Negative value or zero means indefinitely.pScene
- If non-null
, Cursor.WAIT cursor is set on the scene while waiting on the callable to finish.
-
runAndWait
public static <T> T runAndWait(Callable<T> pCallable, Consumer<Runnable> pExecutor, long pTimeoutMillis, javafx.scene.Scene pScene) Invokes the specified supplier on a background thread and waits without blocking UI. This method must either be called from an input event handler or from the run method of a Runnable passed toPlatform.runLater
. It must not be called during animation or layout processing.- Parameters:
pTimeoutMillis
- Duration in milliseconds to wait before giving up. Negative value or zero means indefinitely.pScene
- If non-null
, Cursor.WAIT cursor is set on the scene while waiting on the callable to finish.
-
runAndWait
Invokes the specified supplier on a background thread and waits without blocking UI. This method must either be called from an input event handler or from the run method of a Runnable passed toPlatform.runLater
. It must not be called during animation or layout processing.- Parameters:
pTimeoutMillis
- Duration in milliseconds to wait before giving up. Negative value or zero means indefinitely.
-
runAndWait
This method must either be called from an input event handler or from the run method of a Runnable passed toPlatform.runLater
. It must not be called during animation or layout processing. -
runAndWait
public static <T> T runAndWait(Callable<T> pCallable, Consumer<Runnable> pExecutor, Runnable pInterruptOp, long pTimeoutMillis) This method must either be called from an input event handler or from the run method of a Runnable passed toPlatform.runLater
. It must not be called during animation or layout processing.- Parameters:
pTimeoutMillis
- Duration in milliseconds to wait before giving up. Negative value or zero means indefinitely.
-
waitForCallbackEvent
There are functions which notify about an event, asynchronously, through a callback specified as a parameter. This method can be used to call such function and wait until the specified callback is executed, without blocking the UI.- Parameters:
pFunction
- A function which executes a function with asynchronous callback argument. The runnable argument of the specified function should be executed inside the callback.
-
waitForCallbackEvent
public static boolean waitForCallbackEvent(Consumer<Runnable> pFunction, long pTimeoutMillis, javafx.scene.Scene pScene) There are functions which notify about an event, asynchronously, through a callback specified as a parameter. This method can be used to call such function and wait until the specified callback is executed, without blocking the UI.- Parameters:
pFunction
- A function which executes a function with asynchronous callback argument. The runnable argument of the specified function should be executed inside the callback.pTimeoutMillis
- Duration in milliseconds to wait before giving up. Negative value or zero means indefinitely.pScene
- If non-null
, Cursor.WAIT cursor is set on the scene while waiting on the callable to finish.
-
waitForCallbackResult
There are functions which notify about an event, asynchronously, through a callback specified as a parameter. This method can be used to call such function and wait until the specified callback is executed, without blocking the UI.- Parameters:
pFunction
- A function which executes a function with asynchronous callback argument. The consumer argument of the specified function should be executed inside the callback.
-
waitForCallbackResult
public static <T> T waitForCallbackResult(Consumer<Consumer<T>> pFunction, long pTimeoutMillis, javafx.scene.Scene pScene) There are functions which notify about an event, asynchronously, through a callback specified as a parameter. This method can be used to call such function and wait until the specified callback is executed, without blocking the UI.- Parameters:
pFunction
- A function which executes a function with asynchronous callback argument. The consumer argument of the specified function should be executed inside the callback.pTimeoutMillis
- Duration in milliseconds to wait before giving up. Negative value or zero means indefinitely.pScene
- If non-null
, Cursor.WAIT cursor is set on the scene while waiting on the callable to finish.
-
callOnJavaFxThread
-
runOnJavaFxThreadAndWait
-
mapOnJavaFxThread
public static <S,T> void mapOnJavaFxThread(Stream<S> pStream, Function<S, T> pMapper, int pMaxStepDuration, Consumer<T> pConsumer) This method blocks until all elements are processed.- Parameters:
pMapper
- Invoked on the JavaFX thread to map elements.pMaxStepDuration
- If positive, will try to not block the JavaFX thread for more than this duration (in milliseconds), running later multiple times, if needed.pConsumer
- Invoked on the current thread to process the mapped elements.
-
supplyLater
public static <T> void supplyLater(Supplier<T> pSupplier, Consumer<List<T>> pConsumer, int pItemsPerStep, double pMinDuration) Can be invoked on a background thread to supply (on the JavaFX thread) items to the specified consumer on portions.- Type Parameters:
T
- Items to supply. Note that the items are expected to be immutable. Otherwise, additional thread-safety measures should be taken.- Parameters:
pItemsPerStep
- The number of items to collect before supplying them to consumer.pMinDuration
- If greater than zero, multiple steps may be performed to collect items until the specified duration (in milliseconds) elapses. Then the items are supplied to the consumer and start the process again until all items ar supplied.
-
supplyLater
public static <T> void supplyLater(Stream<T> pItemStream, Consumer<List<T>> pConsumer, int pItemsPerStep, double pMinDuration) Can be invoked on a background thread to supply (on the JavaFX thread) items to the specified consumer on portions.- Type Parameters:
T
- Items to supply. Note that the items are expected to be immutable. Otherwise, additional thread-safety measures should be taken.- Parameters:
pItemsPerStep
- The number of items to collect before supplying them to consumer.pMinDuration
- If greater than zero, multiple steps may be performed to collect items until the specified duration (in milliseconds) elapses. Then the items are supplied to the consumer and start the process again until all items ar supplied.
-