}
}
}
+
+ /**
+ * This method attempts to run provided action synchronously in a read action, so that, if possible, it wouldn't impact any pending,
+ * executing or future write actions (for this to work effectively the action should invoke {@link ProgressManager#checkCanceled()} or
+ * {@link ProgressIndicator#checkCanceled()} often enough).
+ * It returns <code>true</code> if action was executed successfully. It returns <code>false</code> if the action was not
+ * executed successfully, i.e. if:
+ * <ul>
+ * <li>write action was in progress when the method was called</li>
+ * <li>write action was pending when the method was called</li>
+ * <li>action started to execute, but was aborted using {@link ProcessCanceledException} when some other thread initiated
+ * write action</li>
+ * </ul>
+ * @since 171.*
+ */
+ public abstract boolean runInReadActionWithWriteActionPriority(@NotNull final Runnable action);
+
}
\ No newline at end of file
}
}
+ @Override
+ public boolean runInReadActionWithWriteActionPriority(@NotNull Runnable action) {
+ ApplicationManager.getApplication().runReadAction(action);
+ return true;
+ }
+
private void registerIndicatorAndRun(@NotNull ProgressIndicator indicator,
@NotNull Thread currentThread,
ProgressIndicator oldIndicator,
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.progress.*;
+import com.intellij.openapi.progress.util.ProgressIndicatorUtils;
import com.intellij.openapi.progress.util.ProgressWindow;
import com.intellij.openapi.progress.util.SmoothProgressAdapter;
import com.intellij.openapi.util.Disposer;
return ApplicationManager.getApplication().executeOnPooledThread(action);
}
+
+ @Override
+ public boolean runInReadActionWithWriteActionPriority(@NotNull Runnable action) {
+ boolean success = ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(action);
+ if (!success) {
+ ProgressIndicatorUtils.yieldToPendingWriteActions();
+ }
+ return success;
+ }
}