public final class BackgroundTaskUtil
extends java.lang.Object
Constructor and Description |
---|
BackgroundTaskUtil() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
computeInBackgroundAndTryWait(Computable<? extends T> computable,
Consumer<? super T> asyncCallback,
long waitMillis) |
static ProgressIndicator |
executeAndTryWait(Function<? super ProgressIndicator,? extends java.lang.Runnable> backgroundTask,
java.lang.Runnable onSlowAction) |
static ProgressIndicator |
executeAndTryWait(Function<? super ProgressIndicator,? extends java.lang.Runnable> backgroundTask,
java.lang.Runnable onSlowAction,
long waitMillis,
boolean forceEDT)
Executor to perform possibly long operation on pooled thread.
|
static ProgressIndicator |
executeOnPooledThread(Disposable parent,
java.lang.Runnable runnable)
An alternative to plain
Application.executeOnPooledThread(Runnable) which wraps the task in a process with a
ProgressIndicator which gets cancelled when the given disposable is disposed. |
static void |
runUnderDisposeAwareIndicator(Disposable parent,
java.lang.Runnable task) |
static <T> T |
runUnderDisposeAwareIndicator(Disposable parent,
java.util.function.Supplier<T> task) |
static <L> L |
syncPublisher(Project project,
Topic<L> topic)
Wraps
MessageBus.syncPublisher(Topic) in a dispose check,
and throws a ProcessCanceledException if the project is disposed,
instead of throwing an assertion which would happen otherwise. |
static <L> L |
syncPublisher(Topic<L> topic)
Wraps
MessageBus.syncPublisher(Topic) in a dispose check,
and throws a ProcessCanceledException if the application is disposed,
instead of throwing an assertion which would happen otherwise. |
static <T> T |
tryComputeFast(Function<? super ProgressIndicator,? extends T> backgroundTask,
long waitMillis)
Try to compute value in background and abort computation if it takes too long.
|
public static ProgressIndicator executeAndTryWait(Function<? super ProgressIndicator,? extends java.lang.Runnable> backgroundTask, java.lang.Runnable onSlowAction)
public static ProgressIndicator executeAndTryWait(Function<? super ProgressIndicator,? extends java.lang.Runnable> backgroundTask, java.lang.Runnable onSlowAction, long waitMillis, boolean forceEDT)
onSlowAction
will not be executed at all.
It can be used to reduce blinking when background task might be completed fast.
A Simple approach:
onSlowAction.run() // show "Loading..." executeOnPooledThread({ Runnable callback = backgroundTask(); // some background computations invokeLater(callback); // apply changes });will lead to "Loading..." visible between current moment and execution of invokeLater() event. This period can be very short and looks like 'jumping' if background operation is fast.
public static <T> T tryComputeFast(Function<? super ProgressIndicator,? extends T> backgroundTask, long waitMillis)
public static <T> T computeInBackgroundAndTryWait(Computable<? extends T> computable, Consumer<? super T> asyncCallback, long waitMillis)
public static ProgressIndicator executeOnPooledThread(Disposable parent, java.lang.Runnable runnable)
Application.executeOnPooledThread(Runnable)
which wraps the task in a process with a
ProgressIndicator
which gets cancelled when the given disposable is disposed. ProgressManager.checkCanceled()
and avoid Already Disposed exceptions (in particular, because checkCanceled() is called in ServiceManager.getService(Class)
.public static <T> T runUnderDisposeAwareIndicator(Disposable parent, java.util.function.Supplier<T> task)
public static void runUnderDisposeAwareIndicator(Disposable parent, java.lang.Runnable task)
public static <L> L syncPublisher(Project project, Topic<L> topic) throws ProcessCanceledException
MessageBus.syncPublisher(Topic)
in a dispose check,
and throws a ProcessCanceledException
if the project is disposed,
instead of throwing an assertion which would happen otherwise.ProcessCanceledException
syncPublisher(Topic)
public static <L> L syncPublisher(Topic<L> topic) throws ProcessCanceledException
MessageBus.syncPublisher(Topic)
in a dispose check,
and throws a ProcessCanceledException
if the application is disposed,
instead of throwing an assertion which would happen otherwise.ProcessCanceledException
syncPublisher(Project, Topic)