ProgressManager: allow to run tasks from non-EDT thread

This commit is contained in:
Aleksey Pivovarov
2016-06-30 12:58:12 +03:00
committed by Aleksey Pivovarov
parent d59e708e79
commit aa78093cc9
2 changed files with 34 additions and 4 deletions
@@ -317,19 +317,49 @@ public class CoreProgressManager extends ProgressManager implements Disposable {
}
}
else if (task.isModal()) {
runProcessWithProgressSynchronously(task.asModal(), null);
runSynchronously(task.asModal());
}
else {
final Task.Backgroundable backgroundable = task.asBackgroundable();
if (backgroundable.isConditionalModal() && !backgroundable.shouldStartInBackground()) {
runProcessWithProgressSynchronously(task, null);
runSynchronously(task);
}
else {
runProcessWithProgressAsynchronously(backgroundable);
runAsynchronously(backgroundable);
}
}
}
private void runSynchronously(@NotNull final Task task) {
Runnable runnable = new Runnable() {
@Override
public void run() {
runProcessWithProgressSynchronously(task, null);
}
};
if (ApplicationManager.getApplication().isDispatchThread()) {
runnable.run();
}
else {
ApplicationManager.getApplication().invokeAndWait(runnable, ModalityState.NON_MODAL);
}
}
private void runAsynchronously(@NotNull final Task.Backgroundable task) {
Runnable runnable = new Runnable() {
@Override
public void run() {
runProcessWithProgressAsynchronously(task);
}
};
if (ApplicationManager.getApplication().isDispatchThread()) {
runnable.run();
}
else {
ApplicationManager.getApplication().invokeLater(runnable, ModalityState.NON_MODAL);
}
}
@NotNull
public Future<?> runProcessWithProgressAsynchronously(@NotNull Task.Backgroundable task) {
return runProcessWithProgressAsynchronously(task, new EmptyProgressIndicator(), null);
+1 -1
View File
@@ -168,7 +168,7 @@ public class GitVcs extends AbstractVcs<CommittedChangeList> {
* @param task the task to run
*/
public static void runInBackground(Task.Backgroundable task) {
UIUtil.invokeLaterIfNeeded(() -> task.queue());
task.queue();
}
@Override