Skip to content

Commit 82cf150

Browse files
committed
refactor: encapsulate running code in a background thread from a blocking context
This will make refactoring to coroutines easier in the future.
1 parent d853942 commit 82cf150

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/main/kotlin/com/github/lppedd/cc/CCExtensions.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ internal inline fun runInWriteActionIfNeeded(noinline block: () -> Unit) {
407407
}
408408
}
409409

410+
@InlineOnly
411+
internal inline fun runInBackgroundThread(noinline block: () -> Unit) =
412+
ApplicationManager.getApplication().executeOnPooledThread(block)
413+
410414
@InlineOnly
411415
internal inline fun invokeLaterOnEdt(noinline block: () -> Unit) {
412416
ApplicationManager.getApplication().invokeLater(block)

src/main/kotlin/com/github/lppedd/cc/configuration/CCMainConfigurable.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package com.github.lppedd.cc.configuration
33
import com.github.lppedd.cc.CC
44
import com.github.lppedd.cc.CCBundle
55
import com.github.lppedd.cc.invokeLaterOnEdt
6-
import com.intellij.openapi.application.ApplicationManager
6+
import com.github.lppedd.cc.runInBackgroundThread
77
import com.intellij.openapi.diagnostic.logger
88
import com.intellij.openapi.options.SearchableConfigurable
99
import com.intellij.openapi.project.Project
@@ -38,7 +38,7 @@ internal class CCMainConfigurable(private val project: Project) : SearchableConf
3838
gui.customTokensFilePath = configService.customFilePath
3939
gui.customCoAuthorsFilePath = configService.customCoAuthorsFilePath
4040

41-
ApplicationManager.getApplication().executeOnPooledThread {
41+
runInBackgroundThread {
4242
val tokensService = CCTokensService.getInstance(project)
4343
val tokens = when (val result = tokensService.getTokens()) {
4444
is TokensResult.Success -> result.tokens
@@ -81,7 +81,7 @@ internal class CCMainConfigurable(private val project: Project) : SearchableConf
8181
configService.customCoAuthorsFilePath = gui.customCoAuthorsFilePath
8282
configService.customFilePath = gui.customTokensFilePath
8383

84-
ApplicationManager.getApplication().executeOnPooledThread {
84+
runInBackgroundThread {
8585
val tokensService = CCTokensService.getInstance(project)
8686
val result = tokensService.getTokens()
8787

src/main/kotlin/com/github/lppedd/cc/vcs/VcsStartupActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.lppedd.cc.vcs
22

33
import com.github.lppedd.cc.CCRegistry
4-
import com.intellij.openapi.application.ApplicationManager
4+
import com.github.lppedd.cc.runInBackgroundThread
55
import com.intellij.openapi.project.DumbAware
66
import com.intellij.openapi.project.Project
77
import com.intellij.openapi.startup.ProjectActivity
@@ -15,7 +15,7 @@ internal class VcsStartupActivity : ProjectActivity, DumbAware {
1515
override suspend fun execute(project: Project) {
1616
val vcsConfigListener = VcsListener {
1717
if (CCRegistry.isVcsSupportEnabled()) {
18-
ApplicationManager.getApplication().executeOnPooledThread {
18+
runInBackgroundThread {
1919
val vcsHandler = VcsService.getInstance(project)
2020
vcsHandler.refresh()
2121
}

0 commit comments

Comments
 (0)