Rename UserPushStoreFactory.create to UserPushStoreFactory.getOrCreate for code clarity.

This commit is contained in:
Benoit Marty 2024-04-02 16:23:57 +02:00 committed by Benoit Marty
parent e18e5f1cc5
commit 52c039d676
11 changed files with 13 additions and 13 deletions

View file

@ -40,11 +40,11 @@ class DefaultUserPushStoreFactoryTest {
val userPushStoreFactory = DefaultUserPushStoreFactory(context, NoOpSessionObserver())
var userPushStore1: UserPushStore? = null
val thread1 = thread {
userPushStore1 = userPushStoreFactory.create(sessionId)
userPushStore1 = userPushStoreFactory.getOrCreate(sessionId)
}
var userPushStore2: UserPushStore? = null
val thread2 = thread {
userPushStore2 = userPushStoreFactory.create(sessionId)
userPushStore2 = userPushStoreFactory.getOrCreate(sessionId)
}
thread1.join()
thread2.join()

View file

@ -41,7 +41,7 @@ class DefaultUserPushStoreFactory @Inject constructor(
// We can have only one class accessing a single data store, so keep a cache of them.
private val cache = ConcurrentHashMap<SessionId, UserPushStore>()
override fun create(userId: SessionId): UserPushStore {
override fun getOrCreate(userId: SessionId): UserPushStore {
return cache.getOrPut(userId) {
UserPushStoreDataStore(
context = context,
@ -60,6 +60,6 @@ class DefaultUserPushStoreFactory @Inject constructor(
override suspend fun onSessionDeleted(userId: String) {
// Delete the store
create(SessionId(userId)).reset()
getOrCreate(SessionId(userId)).reset()
}
}