Last active
October 17, 2023 17:29
-
-
Save igorescodro/fcbbc4ef8682dd4350b92e79bcc3b8bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private lateinit var dataStore: DataStore<Preferences> | |
private val lock = SynchronizedObject() | |
fun getDataStore(producePath: () -> String): DataStore<Preferences> = | |
synchronized(lock) { | |
if (::dataStore.isInitialized) { | |
dataStore | |
} else { | |
PreferenceDataStoreFactory.createWithPath( | |
produceFile = { producePath().toPath() }, | |
).also { dataStore = it } | |
} | |
} | |
internal const val dataStoreFileName = "settings.preferences_pb" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment