Move inProgress lock at the onFinish of background task (KT-34688)
Setting inProgress to false inside run method can lead to multiple notifications because of delay between run method end and progress hide ^KT-34688 Fixed
This commit is contained in:
@@ -56,26 +56,30 @@ abstract class AsyncScriptDefinitionsContributor(protected val project: Project)
|
|||||||
private var _definitions: List<ScriptDefinition>? = null
|
private var _definitions: List<ScriptDefinition>? = null
|
||||||
private val definitionsLock = ReentrantReadWriteLock()
|
private val definitionsLock = ReentrantReadWriteLock()
|
||||||
|
|
||||||
|
@Volatile
|
||||||
protected var forceStartUpdate = false
|
protected var forceStartUpdate = false
|
||||||
|
|
||||||
|
@Volatile
|
||||||
protected var shouldStartNewUpdate = false
|
protected var shouldStartNewUpdate = false
|
||||||
|
|
||||||
private var inProgress = false
|
private var inProgress = false
|
||||||
private val inProgressLock = ReentrantReadWriteLock()
|
private val inProgressLock = ReentrantReadWriteLock()
|
||||||
|
|
||||||
private inner class DefinitionsCollectorBackgroundTask : Task.Backgroundable(project, progressMessage, true) {
|
private inner class DefinitionsCollectorBackgroundTask : Task.Backgroundable(project, progressMessage, true) {
|
||||||
|
override fun onFinished() {
|
||||||
|
inProgressLock.write {
|
||||||
|
inProgress = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun run(indicator: ProgressIndicator) {
|
override fun run(indicator: ProgressIndicator) {
|
||||||
while (true) {
|
while (true) {
|
||||||
inProgressLock.read {
|
if (indicator.isCanceled || !shouldStartNewUpdate) {
|
||||||
if (indicator.isCanceled || !shouldStartNewUpdate) {
|
return
|
||||||
inProgressLock.write {
|
|
||||||
inProgress = false
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
shouldStartNewUpdate = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shouldStartNewUpdate = false
|
||||||
|
|
||||||
val previousDefinitions = definitionsLock.read {
|
val previousDefinitions = definitionsLock.read {
|
||||||
if (!forceStartUpdate && _definitions != null) return
|
if (!forceStartUpdate && _definitions != null) return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user