-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide dispatchers instead of harcoding
- Loading branch information
Showing
4 changed files
with
71 additions
and
23 deletions.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
app/src/main/java/dev/arkbuilders/navigator/di/modules/DispatcherModule.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dev.arkbuilders.navigator.di.modules | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.Dispatchers | ||
import javax.inject.Qualifier | ||
@Module | ||
class DispatcherModule { | ||
|
||
@DefaultDispatcher | ||
@Provides | ||
fun providesDefaultDispatcher(): CoroutineDispatcher = Dispatchers.Default | ||
|
||
@IoDispatcher | ||
@Provides | ||
fun providesIoDispatcher(): CoroutineDispatcher = Dispatchers.IO | ||
|
||
@MainDispatcher | ||
@Provides | ||
fun providesMainDispatcher(): CoroutineDispatcher = Dispatchers.Main | ||
} | ||
|
||
@Retention(AnnotationRetention.BINARY) | ||
@Qualifier | ||
annotation class DefaultDispatcher | ||
|
||
@Retention(AnnotationRetention.BINARY) | ||
@Qualifier | ||
annotation class IoDispatcher | ||
|
||
@Retention(AnnotationRetention.BINARY) | ||
@Qualifier | ||
annotation class MainDispatcher |
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
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