Skip to content

Instantly share code, notes, and snippets.

@RBusarow
Created January 11, 2020 22:49
Show Gist options
  • Save RBusarow/92fc47e7c3ecc2ee3a69a4fd7d796966 to your computer and use it in GitHub Desktop.
Save RBusarow/92fc47e7c3ecc2ee3a69a4fd7d796966 to your computer and use it in GitHub Desktop.
Examples of Dagger2 and Koin modules for providing dispatcher-specific CoroutineScopes.
@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()
}
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