Created
May 28, 2022 06:53
-
-
Save AndroidPoet/f783280d925392ec45315c00a9572395 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
//interface | |
interface CoroutineDispatcherProvider { | |
val main: CoroutineDispatcher | |
val io: CoroutineDispatcher | |
val default: CoroutineDispatcher | |
val unconfirmed: CoroutineDispatcher | |
} | |
//initialization using "by lazy" | |
open class RealCoroutineDispatcherProvider : CoroutineDispatcherProvider { | |
override val main: CoroutineDispatcher by lazy { Dispatchers.Main } | |
override val io: CoroutineDispatcher by lazy { Dispatchers.IO } | |
override val default: CoroutineDispatcher by lazy { Dispatchers.Default } | |
override val unconfirmed: CoroutineDispatcher by lazy { Dispatchers.Unconfined } | |
} | |
//DI Module " | |
@InstallIn(SingletonComponent::class) | |
@Module | |
class DispatcherModule { | |
@Provides | |
@Singleton | |
fun providesCoroutineDispatcher(): CoroutineDispatcherProvider { | |
return RealCoroutineDispatcherProvider() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment