@@ -33,17 +33,19 @@ import com.intellij.openapi.project.Project
33
33
import com.intellij.openapi.roots.ProjectRootManager
34
34
import com.intellij.openapi.util.CheckedDisposable
35
35
import com.intellij.openapi.vfs.VfsUtil
36
+ import kotlinx.coroutines.CoroutineScope
37
+ import kotlinx.coroutines.launch
36
38
import org.gradle.tooling.CancellationTokenSource
37
39
import org.gradle.tooling.GradleConnector
38
40
import org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper
39
41
import org.jetbrains.plugins.gradle.settings.GradleExecutionSettings
40
42
import org.jetbrains.plugins.gradle.util.GradleConstants
41
43
import java.io.File
42
- import java.util.concurrent.Executors
43
44
44
45
@Service(Service .Level .PROJECT )
45
46
class ApolloCodegenService (
46
47
private val project : Project ,
48
+ private val coroutineScope : CoroutineScope ,
47
49
) : Disposable {
48
50
private var documentChangesDisposable: CheckedDisposable ? = null
49
51
private var fileEditorChangesDisposable: CheckedDisposable ? = null
@@ -53,8 +55,6 @@ class ApolloCodegenService(
53
55
54
56
private var gradleCodegenCancellation: CancellationTokenSource ? = null
55
57
56
- private val gradleExecutorService = Executors .newSingleThreadExecutor()
57
-
58
58
init {
59
59
logd(" project=${project.name} " )
60
60
startOrStopCodegenObservers()
@@ -181,10 +181,9 @@ class ApolloCodegenService(
181
181
182
182
val modules = ModuleManager .getInstance(project).modules
183
183
val rootProjectPath = project.getGradleRootPath() ? : return
184
- val executionSettings =
185
- ExternalSystemApiUtil .getExecutionSettings<GradleExecutionSettings >(project, rootProjectPath, GradleConstants .SYSTEM_ID )
186
-
187
- gradleExecutorService.submit {
184
+ coroutineScope.launch {
185
+ val executionSettings =
186
+ ExternalSystemApiUtil .getExecutionSettings<GradleExecutionSettings >(project, rootProjectPath, GradleConstants .SYSTEM_ID )
188
187
val gradleExecutionHelper = GradleExecutionHelper ()
189
188
gradleExecutionHelper.execute(rootProjectPath, executionSettings) { connection ->
190
189
gradleCodegenCancellation = GradleConnector .newCancellationTokenSource()
@@ -257,6 +256,5 @@ class ApolloCodegenService(
257
256
override fun dispose () {
258
257
logd(" project=${project.name} " )
259
258
stopContinuousGradleCodegen()
260
- gradleExecutorService.shutdown()
261
259
}
262
260
}
0 commit comments