Skip to content

Commit

Permalink
Make value volatile
Browse files Browse the repository at this point in the history
  • Loading branch information
ofekby committed Nov 22, 2023
1 parent 82d83a3 commit 66cf175
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ package com.tabnineCommon.general
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.util.messages.Topic
import java.util.Optional
import java.util.*
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.locks.Lock
import java.util.concurrent.locks.ReadWriteLock
import java.util.concurrent.locks.ReentrantReadWriteLock
import java.util.function.Consumer

open class TopicBasedState<T, S : Consumer<T>>(private val topic: Topic<S>, private var value: T? = null) {
open class TopicBasedState<T, S : Consumer<T>>(
private val topic: Topic<S>,
@Volatile
private var value: T? = null
) {
private val rwLock: ReadWriteLock = ReentrantReadWriteLock()
private val hasChanged = AtomicBoolean(false)

Expand Down Expand Up @@ -39,7 +43,8 @@ open class TopicBasedState<T, S : Consumer<T>>(private val topic: Topic<S>, priv
subscription.accept(value!!)
}

ApplicationManager.getApplication().messageBus.connect(parent).subscribe(topic, subscription)
ApplicationManager.getApplication().messageBus.connect(parent)
.subscribe(topic, subscription)
}
}

Expand Down

0 comments on commit 66cf175

Please sign in to comment.