Skip to content

Commit

Permalink
fix(devins-lang): fix asynchronous execution issue #100
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
phodal committed Mar 21, 2024
1 parent 911384f commit 2fc3b52
Showing 1 changed file with 10 additions and 1 deletion.
Expand Up @@ -7,7 +7,9 @@ import com.intellij.execution.runners.ExecutionEnvironment
import com.intellij.execution.runners.GenericProgramRunner
import com.intellij.execution.runners.showRunContent
import com.intellij.execution.ui.RunContentDescriptor
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.fileEditor.FileDocumentManager
import java.util.concurrent.atomic.AtomicReference

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

val result = AtomicReference<RunContentDescriptor>()
FileDocumentManager.getInstance().saveAllDocuments()
return showRunContent(state.execute(environment.executor, this), environment)

ApplicationManager.getApplication().invokeAndWait {
val showRunContent = showRunContent(state.execute(environment.executor, this), environment)
result.set(showRunContent)
}

return result.get()
}
}

0 comments on commit 2fc3b52

Please sign in to comment.