mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-07 20:36:05 +00:00
Use ConcurrentHashMap to manage synchronization.
This commit is contained in:
+3
-4
@@ -26,6 +26,7 @@ import io.element.android.libraries.pushstore.api.UserPushStore
|
||||
import io.element.android.libraries.pushstore.api.UserPushStoreFactory
|
||||
import io.element.android.libraries.sessionstorage.api.observer.SessionListener
|
||||
import io.element.android.libraries.sessionstorage.api.observer.SessionObserver
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import javax.inject.Inject
|
||||
|
||||
@SingleIn(AppScope::class)
|
||||
@@ -39,17 +40,15 @@ class DefaultUserPushStoreFactory @Inject constructor(
|
||||
}
|
||||
|
||||
// We can have only one class accessing a single data store, so keep a cache of them.
|
||||
private val cache = mutableMapOf<SessionId, UserPushStore>()
|
||||
private val cache = ConcurrentHashMap<SessionId, UserPushStore>()
|
||||
override fun create(userId: SessionId): UserPushStore {
|
||||
return synchronized(cache) {
|
||||
cache.getOrPut(userId) {
|
||||
return cache.getOrPut(userId) {
|
||||
UserPushStoreDataStore(
|
||||
context = context,
|
||||
userId = userId
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun observeSessions() {
|
||||
sessionObserver.addListener(this)
|
||||
|
||||
Reference in New Issue
Block a user