-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add suspend room db accessor #115
Comments
Example of home grown technique: private val someDb by lazy { roomDb<SomethingDatabase>("something") }
suspend fun someDb() = withContext(ioDispatcher) { someDb } With such a function: suspend operator fun <T : RoomDatabase> Lazy<T>.invoke(): T = if (isInitialized()) value
else withContext(ioDispatcher) { value } this can be reduced to this: val someDb = lazy { roomDb<SomethingDatabase>("some") } // Client code |
The |
Here's an implementation of this issue in the sample sources: Splitties/sample/src/main/java/com/louiscad/splittiessample/extensions/coroutines/SuspendLazyRoom.kt Lines 9 to 19 in 8510b5a
|
The Splitties/sample/src/main/java/com/louiscad/splittiessample/extensions/coroutines/SuspendLazy.kt Lines 7 to 15 in 4b444d0
Here's how it can be used for Room: Splitties/sample/src/main/java/com/louiscad/splittiessample/extensions/coroutines/SuspendLazyRoom.kt Lines 8 to 11 in 4b444d0
it can also be used for SharedPreferences: Splitties/sample/src/main/java/com/louiscad/splittiessample/prefs/GamePreferences.kt Lines 23 to 24 in 4b444d0
|
No description provided.
The text was updated successfully, but these errors were encountered: