forked from bazelbuild/intellij
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Reduce freeze in ProjectUpdater (bazelbuild#7153)
* fix: Reduce freeze in ProjectUpdater closes bazelbuild#7149 * Allow to switch back to the old behavior (just in case)
- Loading branch information
Tomasz Pasternak
authored
Dec 11, 2024
1 parent
f5f8f24
commit bdb2b48
Showing
3 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
base/src/com/google/idea/blaze/base/qsync/ProjectUpdaterThreadingUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.google.idea.blaze.base.qsync | ||
|
||
import com.google.idea.common.util.Transactions | ||
import com.intellij.openapi.application.readAndWriteAction | ||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.openapi.util.registry.Registry | ||
import kotlinx.coroutines.runBlocking | ||
import java.util.concurrent.Callable | ||
import java.util.function.Consumer | ||
|
||
class ProjectUpdaterThreadingUtils { | ||
companion object { | ||
val logger = Logger.getInstance(ProjectUpdaterThreadingUtils::class.java) | ||
fun <T> readWriteAction(readPart: Callable<T>, commit: Consumer<T>) { | ||
if (Registry.`is`("bazel.qsync.enable.coroutine.project.updater")) { | ||
runBlocking { | ||
readAndWriteAction { | ||
logger.info("Starting read operation") | ||
val ret = readPart.call() | ||
writeAction { | ||
commit.accept(ret) | ||
} | ||
} | ||
} | ||
} else { | ||
Transactions.submitWriteActionTransactionAndWait { | ||
val ret = readPart.call() | ||
commit.accept(ret) | ||
} | ||
} | ||
} | ||
} | ||
} |