getOrPut is not thread safe, so ensure that no multiple instance will be created per data store (#950)
This commit is contained in:
parent
3e4ff90e99
commit
3457a76446
1 changed files with 7 additions and 5 deletions
|
|
@ -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
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue