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 val definitionsLock = ReentrantReadWriteLock()
|
||||
|
||||
@Volatile
|
||||
protected var forceStartUpdate = false
|
||||
|
||||
@Volatile
|
||||
protected var shouldStartNewUpdate = false
|
||||
|
||||
private var inProgress = false
|
||||
private val inProgressLock = ReentrantReadWriteLock()
|
||||
|
||||
private inner class DefinitionsCollectorBackgroundTask : Task.Backgroundable(project, progressMessage, true) {
|
||||
override fun onFinished() {
|
||||
inProgressLock.write {
|
||||
inProgress = false
|
||||
}
|
||||
}
|
||||
|
||||
override fun run(indicator: ProgressIndicator) {
|
||||
while (true) {
|
||||
inProgressLock.read {
|
||||
if (indicator.isCanceled || !shouldStartNewUpdate) {
|
||||
inProgressLock.write {
|
||||
inProgress = false
|
||||
}
|
||||
return
|
||||
}
|
||||
shouldStartNewUpdate = false
|
||||
if (indicator.isCanceled || !shouldStartNewUpdate) {
|
||||
return
|
||||
}
|
||||
|
||||
shouldStartNewUpdate = false
|
||||
|
||||
val previousDefinitions = definitionsLock.read {
|
||||
if (!forceStartUpdate && _definitions != null) return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user