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) |
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( |
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) |
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() | |
} |
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 |
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 | |
) { | |
... | |
} |
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 |
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) | |
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 { | |
... | |
} | |
} |
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