Created
January 11, 2020 22:49
-
-
Save RBusarow/92fc47e7c3ecc2ee3a69a4fd7d796966 to your computer and use it in GitHub Desktop.
Examples of Dagger2 and Koin modules for providing dispatcher-specific CoroutineScopes.
This file contains hidden or 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
@Module | |
object CoroutineScopeModule { | |
@Provides | |
fun provideDefaultCoroutineScope(): DefaultCoroutineScope = DefaultCoroutineScope() | |
@Provides | |
fun provideIOCoroutineScope(): IOCoroutineScope = IOCoroutineScope() | |
@Provides | |
fun provideMainCoroutineScope(): MainCoroutineScope = MainCoroutineScope() | |
@Provides | |
fun provideMainImmediateCoroutineScope(): MainCoroutineScope = MainImmediateCoroutineScope() | |
@Provides | |
fun provideUnconfinedCoroutineScope(): MainCoroutineScope = UnconfinedCoroutineScope() | |
} |
This file contains hidden or 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
val coroutineScopeModule = module { | |
factory<DefaultCoroutineScope> { DefaultCoroutineScope() } | |
factory<IOCoroutineScope> { IOCoroutineScope() } | |
factory<MainCoroutineScope> { MainCoroutineScope() } | |
factory<MainImmediateCoroutineScope> { MainImmediateCoroutineScope() } | |
factory<UnconfinedCoroutineScope> { UnconfinedCoroutineScope() } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment