View CoroutineTestRule.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
class CoroutineTestRule : TestRule, | |
TestPolymorphicCoroutineScope by TestPolymorphicCoroutineScope() { | |
val dispatcher = coroutineContext[ContinuationInterceptor] as TestCoroutineDispatcher | |
override fun apply( | |
base: Statement, description: Description? | |
) = object : Statement() { | |
override fun evaluate() { | |
@Throws(Throwable::class) |
View TestPolymorphicCoroutineScope.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
@ExperimentalCoroutinesApi | |
interface TestPolymorphicCoroutineScope : TestCoroutineScope, | |
DefaultCoroutineScope, | |
IOCoroutineScope, | |
MainCoroutineScope, | |
MainImmediateCoroutineScope, | |
UnconfinedCoroutineScope | |
@ExperimentalCoroutinesApi | |
private class TestPolymorphicCoroutineScopeImpl( |
View MainScopeCreation.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
val scope = MainCoroutineScope() | |
val progressIndicator = ProgressIndicator(scope) |
View CoroutineScopeModule.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
@Module | |
object CoroutineScopeModule { | |
@Provides | |
fun provideMainCoroutineScope(): MainCoroutineScope = MainCoroutineScope() | |
} |
View CoroutineScopeFactories.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
public fun MainCoroutineScope( | |
job: Job = SupervisorJob() | |
): MainCoroutineScope = object : MainCoroutineScope { | |
override val coroutineContext = job + Dispatchers.Main | |
} | |
public fun MainCoroutineScope( | |
context: CoroutineContext | |
): MainCoroutineScope = object : MainCoroutineScope { | |
override val coroutineContext = context + Dispatchers.Main |
View ProgressIndicator.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
class ProgressIndicator( | |
private val coroutineScope: MainCoroutineScope | |
) { | |
... | |
} |
View CoroutineScopes.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
interface DefaultCoroutineScope : CoroutineScope | |
interface IOCoroutineScope : CoroutineScope | |
interface MainCoroutineScope : CoroutineScope | |
interface MainImmediateCoroutineScope : CoroutineScope | |
interface UnconfinedCoroutineScope : CoroutineScope |
View Dagger2QualifiedCoroutineScope.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
@Qualifier | |
annotation class MainCoroutineScope | |
@Module | |
object CoroutineScopeModule { | |
@Provides | |
@MainCoroutineScope | |
fun provideMainCoroutineScope(): CoroutineScope = CoroutineScope(Job() + Dispatchers.Main) | |
View ProgressIndicator.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
class ProgressIndicator( | |
private val coroutineScope: CoroutineScope | |
) { | |
fun start( | |
timeout: Milliseconds, | |
message: String? = null | |
) = coroutineScope.launch { | |
... | |
} | |
} |
View MyCoroutineScope.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
class MyCoroutineScope : CoroutineScope { | |
override val coroutineContext = Job() + Dispatchers.Main | |
} | |
val someScope = CoroutineScope(Job() + Dispatchers.IO) |
NewerOlder