All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.net.folivo.trixnity.client.store.RootStore.kt Maven / Gradle / Ivy

There is a newer version: 4.7.1
Show newest version
package net.folivo.trixnity.client.store

import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.getAndUpdate
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock

class RootStore(private val stores: List) : Store {
    private val hasBeenInit = MutableStateFlow(false)
    override suspend fun init() {
        if (hasBeenInit.getAndUpdate { true }.not())
            stores.forEach { it.init() }
    }

    private val clearCacheMutex = Mutex()
    override suspend fun clearCache() {
        clearCacheMutex.withLock {
            stores.forEach { it.init() }
        }
    }

    private val deleteAllMutex = Mutex()
    override suspend fun deleteAll() {
        deleteAllMutex.withLock {
            stores.forEach { it.deleteAll() }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy