mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 01:47:03 +05:30
feat: separate db reads and writes to separate dispatchers
This commit is contained in:
parent
f818da6f64
commit
976c9dd064
5 changed files with 38 additions and 20 deletions
|
@ -21,8 +21,11 @@ interface DispatcherProvider {
|
|||
|
||||
fun io(): CoroutineDispatcher = Dispatchers.IO
|
||||
|
||||
fun database(): CoroutineDispatcher =
|
||||
Dispatchers.IO.limitedParallelism(1, name = "DatabaseDispatcher")
|
||||
fun databaseRead(): CoroutineDispatcher =
|
||||
Dispatchers.IO.limitedParallelism(4, name = "DatabaseRead")
|
||||
|
||||
fun databaseWrite(): CoroutineDispatcher =
|
||||
Dispatchers.IO.limitedParallelism(1, name = "DatabaseWrite")
|
||||
}
|
||||
|
||||
/** Concrete type for [DispatcherProvider] with all the defaults from the class. */
|
||||
|
|
|
@ -16,7 +16,9 @@ import dev.msfjarvis.claw.core.coroutines.DispatcherProvider
|
|||
import javax.inject.Qualifier
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
|
||||
@Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class DatabaseDispatcher
|
||||
@Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class DatabaseReadDispatcher
|
||||
|
||||
@Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class DatabaseWriteDispatcher
|
||||
|
||||
@Qualifier @Retention(AnnotationRetention.RUNTIME) annotation class MainDispatcher
|
||||
|
||||
|
@ -36,9 +38,16 @@ interface CoroutineDispatcherModule {
|
|||
return dispatcherProvider.io()
|
||||
}
|
||||
|
||||
@[Provides DatabaseDispatcher]
|
||||
fun provideDatabaseDispatcher(dispatcherProvider: DispatcherProvider): CoroutineDispatcher {
|
||||
return dispatcherProvider.database()
|
||||
@[Provides DatabaseReadDispatcher]
|
||||
fun provideDatabaseReadDispatcher(dispatcherProvider: DispatcherProvider): CoroutineDispatcher {
|
||||
return dispatcherProvider.databaseRead()
|
||||
}
|
||||
|
||||
@[Provides DatabaseWriteDispatcher]
|
||||
fun provideDatabaseWriteDispatcher(
|
||||
dispatcherProvider: DispatcherProvider
|
||||
): CoroutineDispatcher {
|
||||
return dispatcherProvider.databaseWrite()
|
||||
}
|
||||
|
||||
@[Provides MainDispatcher]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue