public class NonBlockingReadActionImpl<T> extends <any> implements NonBlockingReadAction<T>
Modifier and Type | Method and Description |
---|---|
protected NonBlockingReadActionImpl<T> |
cloneWith(ContextConstraint [] constraints,
java.util.function.BooleanSupplier [] cancellationConditions,
java.util.Set<? extends Expiration> expirationSet) |
NonBlockingReadAction<T> |
coalesceBy(java.lang.Object... equality)
Merges together similar computations by cancelling the previous ones when a new one is submitted.
|
void |
dispatchLaterUnconstrained(java.lang.Runnable runnable) |
T |
executeSynchronously()
Run this computation on the current thread in a non-blocking read action, when possible.
|
NonBlockingReadAction<T> |
expireWhen(java.util.function.BooleanSupplier expireCondition)
Returns a copy of this builder that cancels submitted read actions after they become obsolete.
|
NonBlockingReadActionImpl<T> |
expireWith(Disposable parentDisposable) |
NonBlockingReadAction<T> |
finishOnUiThread(ModalityState modality,
java.util.function.Consumer<T> uiThreadAction) |
NonBlockingReadAction<T> |
inSmartMode(Project project) |
CancellablePromise<T> |
submit(java.util.concurrent.Executor backgroundThreadExecutor)
Submit this computation to be performed in a non-blocking read action on background thread.
|
static void |
waitForAsyncTaskCompletion() |
NonBlockingReadAction<T> |
withDocumentsCommitted(Project project) |
NonBlockingReadAction<T> |
wrapProgress(ProgressIndicator progressIndicator) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
cancelWith
protected NonBlockingReadActionImpl<T> cloneWith(ContextConstraint [] constraints, java.util.function.BooleanSupplier [] cancellationConditions, java.util.Set<? extends Expiration> expirationSet)
public void dispatchLaterUnconstrained(java.lang.Runnable runnable)
public NonBlockingReadAction<T> inSmartMode(Project project)
inSmartMode
in interface NonBlockingReadAction<T>
NonBlockingReadAction.finishOnUiThread(com.intellij.openapi.application.ModalityState, java.util.function.Consumer<T>)
runnable
are completed.DumbService
public NonBlockingReadAction<T> withDocumentsCommitted(Project project)
withDocumentsCommitted
in interface NonBlockingReadAction<T>
NonBlockingReadAction.finishOnUiThread(com.intellij.openapi.application.ModalityState, java.util.function.Consumer<T>)
runnable
are completed.PsiDocumentManager
public NonBlockingReadAction<T> expireWhen(java.util.function.BooleanSupplier expireCondition)
NonBlockingReadAction
expireWhen
returns true
).
The conditions are checked when read access is allowed, before the computation on a background thread
and before NonBlockingReadAction.finishOnUiThread(com.intellij.openapi.application.ModalityState, java.util.function.Consumer<T>)
handler, if any.
Even if the expiration condition becomes true
without a write action during the background computation,
it won't be checked until the computation is complete.
Hence if you want to cancel the computation immediately, you should handle that separately
(e.g. by putting CancellablePromise.cancel()
inside some listener).expireWhen
in interface NonBlockingReadAction<T>
public NonBlockingReadActionImpl<T> expireWith(Disposable parentDisposable)
expireWith
in interface NonBlockingReadAction<T>
CancellablePromise
will be canceled immediately, its completion handlers will be called.
Currently running background computations will throw a ProcessCanceledException
on the next checkCanceled
call,
and if computations or NonBlockingReadAction.finishOnUiThread(com.intellij.openapi.application.ModalityState, java.util.function.Consumer<T>)
handlers are scheduled, they won't be executed.public NonBlockingReadAction<T> wrapProgress(ProgressIndicator progressIndicator)
wrapProgress
in interface NonBlockingReadAction<T>
NonBlockingReadAction
.
This means that submitted read actions are cancelled once the outer indicator is cancelled,
and the visual changes (e.g. ProgressIndicator.setText(java.lang.String)
) are propagated from the inner to the outer indicator.public NonBlockingReadAction<T> finishOnUiThread(ModalityState modality, java.util.function.Consumer<T> uiThreadAction)
finishOnUiThread
in interface NonBlockingReadAction<T>
public NonBlockingReadAction<T> coalesceBy(java.lang.Object... equality)
NonBlockingReadAction
coalesceBy
in interface NonBlockingReadAction<T>
equality
- objects that together identify the computation: if they're all equal in two submissions,
then the computations are merged. Callers should take care to pass something unique there
(e.g. some Key
or this
getClass()
),
so that computations from different places won't interfere.public T executeSynchronously() throws ProcessCanceledException
NonBlockingReadAction
NonBlockingReadAction.submit(java.util.concurrent.Executor)
API where possible,
preferably coupled with NonBlockingReadAction.finishOnUiThread(com.intellij.openapi.application.ModalityState, java.util.function.Consumer<T>)
to ensure result validity.
If the current thread already has read access, the computation is executed as is, without any write-action-cancellability.
It's the responsibility of the caller to take care about it.
NonBlockingReadAction.finishOnUiThread(com.intellij.openapi.application.ModalityState, java.util.function.Consumer<T>)
and NonBlockingReadAction.coalesceBy(java.lang.Object...)
are not supported with synchronous non-blocking read actions.executeSynchronously
in interface NonBlockingReadAction<T>
ProcessCanceledException
- if the computation got expired due to NonBlockingReadAction.expireWhen(java.util.function.BooleanSupplier)
or NonBlockingReadAction.expireWith(com.intellij.openapi.Disposable)
or NonBlockingReadAction.wrapProgress(com.intellij.openapi.progress.ProgressIndicator)
.public CancellablePromise<T> submit(java.util.concurrent.Executor backgroundThreadExecutor)
NonBlockingReadAction
NonBlockingReadAction.finishOnUiThread(com.intellij.openapi.application.ModalityState, java.util.function.Consumer<T>)
has been called.submit
in interface NonBlockingReadAction<T>
backgroundThreadExecutor
- an executor to actually run the computation. Common examples are
com.intellij.util.concurrency.NonUrgentExecutor#getInstance()
or
AppExecutorUtil.getAppExecutorService()
or
BoundedTaskExecutor
on top of that.public static void waitForAsyncTaskCompletion()