Skip to content

Instantly share code, notes, and snippets.

@khahani
Created September 17, 2023 16:27
Show Gist options
  • Select an option

  • Save khahani/3b4012cebfaaa97a921b0335c1bb7a20 to your computer and use it in GitHub Desktop.

Select an option

Save khahani/3b4012cebfaaa97a921b0335c1bb7a20 to your computer and use it in GitHub Desktop.
CoroutineScopesModule.kt
import [your_app_package].core.network.Dispatcher
import [your_app_package].core.network.AppDispatchers.Default
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import javax.inject.Qualifier
import javax.inject.Singleton
@Retention(AnnotationRetention.RUNTIME)
@Qualifier
annotation class ApplicationScope
@Module
@InstallIn(SingletonComponent::class)
object CoroutineScopesModule {
@Provides
@Singleton
@ApplicationScope
fun providesCoroutineScope(
@Dispatcher(Default) dispatcher: CoroutineDispatcher,
): CoroutineScope = CoroutineScope(SupervisorJob() + dispatcher)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment