Skip to content

Commit 2fc3b52

Browse files
committed
fix(devins-lang): fix asynchronous execution issue #100
Add atomic reference and use invokeAndWait to ensure proper asynchronous execution, preventing race conditions. This commit fixes an issue in DevInsProgramRunner where asynchronous execution could result in race conditions. By adding an atomic reference and using invokeAndWait, the asynchronous execution is now handled in a thread-safe manner.
1 parent 911384f commit 2fc3b52

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/run/DevInsProgramRunner.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import com.intellij.execution.runners.ExecutionEnvironment
77
import com.intellij.execution.runners.GenericProgramRunner
88
import com.intellij.execution.runners.showRunContent
99
import com.intellij.execution.ui.RunContentDescriptor
10+
import com.intellij.openapi.application.ApplicationManager
1011
import com.intellij.openapi.fileEditor.FileDocumentManager
12+
import java.util.concurrent.atomic.AtomicReference
1113

1214
open class DevInsProgramRunner : GenericProgramRunner<RunnerSettings>() {
1315
companion object {
@@ -21,7 +23,14 @@ open class DevInsProgramRunner : GenericProgramRunner<RunnerSettings>() {
2123
override fun doExecute(state: RunProfileState, environment: ExecutionEnvironment): RunContentDescriptor? {
2224
if (environment.runProfile !is DevInsConfiguration) return null
2325

26+
val result = AtomicReference<RunContentDescriptor>()
2427
FileDocumentManager.getInstance().saveAllDocuments()
25-
return showRunContent(state.execute(environment.executor, this), environment)
28+
29+
ApplicationManager.getApplication().invokeAndWait {
30+
val showRunContent = showRunContent(state.execute(environment.executor, this), environment)
31+
result.set(showRunContent)
32+
}
33+
34+
return result.get()
2635
}
2736
}

0 commit comments

Comments
 (0)