mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:32:34 +00:00
getOrPut is not thread safe, so ensure that no multiple instance will be created per data store (#950)
This commit is contained in:
+7
-5
@@ -41,11 +41,13 @@ class DefaultUserPushStoreFactory @Inject constructor(
|
|||||||
// We can have only one class accessing a single data store, so keep a cache of them.
|
// 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 = mutableMapOf<SessionId, UserPushStore>()
|
||||||
override fun create(userId: SessionId): UserPushStore {
|
override fun create(userId: SessionId): UserPushStore {
|
||||||
return cache.getOrPut(userId) {
|
return synchronized(cache) {
|
||||||
UserPushStoreDataStore(
|
cache.getOrPut(userId) {
|
||||||
context = context,
|
UserPushStoreDataStore(
|
||||||
userId = userId
|
context = context,
|
||||||
)
|
userId = userId
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user