Skip to content

Commit bc57644

Browse files
Merge pull request #11998 from microsoft/fix/nonblocking-read-action
Replace runReadAction with ReadAction.nonBlocking in IntellijAzureTaskManager and AzureArtifact
2 parents a4b261b + 4d8c464 commit bc57644

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

  • PluginsAndFeatures/azure-toolkit-for-intellij

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib-java/src/main/java/com/microsoft/azure/toolkit/intellij/common/AzureArtifact.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
package com.microsoft.azure.toolkit.intellij.common;
77

88
import com.intellij.icons.AllIcons;
9-
import com.intellij.openapi.application.ApplicationManager;
9+
import com.intellij.openapi.application.ReadAction;
1010
import com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo;
1111
import com.intellij.openapi.module.Module;
1212
import com.intellij.openapi.module.ModuleUtil;
1313
import com.intellij.openapi.project.Project;
1414
import com.intellij.openapi.roots.ProjectFileIndex;
15-
import com.intellij.openapi.util.Computable;
1615
import com.intellij.openapi.vfs.LocalFileSystem;
1716
import com.intellij.openapi.vfs.VfsUtil;
1817
import com.intellij.openapi.vfs.VirtualFile;
@@ -129,7 +128,7 @@ public Module getModule() {
129128
if (this.getReferencedObject() == null) {
130129
return null;
131130
}
132-
return ApplicationManager.getApplication().runReadAction((Computable<Module>) () -> switch (type) {
131+
return ReadAction.nonBlocking(() -> switch (type) {
133132
case Gradle -> {
134133
final Path path = Paths.get(((ExternalProjectPojo) referencedObject).getPath());
135134
yield Optional.ofNullable(VfsUtil.findFile(path, true))
@@ -141,7 +140,8 @@ public Module getModule() {
141140
.map(p -> VfsUtil.findFile(p, true))
142141
.map(f -> ProjectFileIndex.getInstance(project).getModuleForFile(f)).orElse(null);
143142
case File -> getNearestParentModuleForFile((VirtualFile) this.getReferencedObject());
144-
});
143+
}).expireWhen(project::isDisposed)
144+
.executeSynchronously();
145145
}
146146

147147
@Nullable

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/java/com/microsoft/azure/toolkit/intellij/common/task/IntellijAzureTaskManager.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.intellij.openapi.application.Application;
99
import com.intellij.openapi.application.ApplicationManager;
1010
import com.intellij.openapi.application.ModalityState;
11+
import com.intellij.openapi.application.ReadAction;
1112
import com.intellij.openapi.components.Service;
1213
import com.intellij.openapi.progress.PerformInBackgroundOption;
1314
import com.intellij.openapi.progress.ProgressIndicator;
@@ -30,7 +31,12 @@ public class IntellijAzureTaskManager extends AzureTaskManager {
3031

3132
@Override
3233
protected void doRead(Runnable runnable, final AzureTask<?> task) {
33-
ApplicationManager.getApplication().runReadAction(runnable);
34+
final Project project = (Project) task.getProject();
35+
final var builder = ReadAction.nonBlocking(runnable);
36+
if (project != null) {
37+
builder.expireWhen(project::isDisposed);
38+
}
39+
builder.executeSynchronously();
3440
}
3541

3642
@Override

0 commit comments

Comments
 (0)