Skip to content

Instantly share code, notes, and snippets.

@meet30997
Last active September 6, 2022 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meet30997/46e8904ae225d21d306f4ebf4be2c37d to your computer and use it in GitHub Desktop.
Save meet30997/46e8904ae225d21d306f4ebf4be2c37d to your computer and use it in GitHub Desktop.
Synchronous DataStore
// Using runBlocking
// It blocks the UI Thread
val userName = runBlocking {
dataStore.data.first()[DataStoreManager.userNameKey]
}
binding.userName.text = userName
// Using UI thread safe lifecycleScope
lifecycleScope.launch {
val userName = dataStoreManager.dataStore.data.first()[DataStoreManager.userNameKey]
binding.userName.text = userName
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment