Skip to content

Commit

Permalink
Deprecate 'TestCoroutineDispatcher'
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhalanskyjb committed Oct 14, 2021
1 parent 9af7f53 commit d1c2768
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kotlinx-coroutines-test/common/src/DelayController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public interface DelayController {
* This is useful when testing functions that start a coroutine. By pausing the dispatcher assertions or
* setup may be done between the time the coroutine is created and started.
*/
@Deprecated(
"Please use a dispatcher that is paused by default, like `StandardTestDispatcher`.",
level = DeprecationLevel.WARNING
)
@ExperimentalCoroutinesApi // Since 1.2.1, tentatively till 1.3.0
public suspend fun pauseDispatcher(block: suspend () -> Unit)

Expand All @@ -109,6 +113,10 @@ public interface DelayController {
* When paused, the dispatcher will not execute any coroutines automatically, and you must call [runCurrent] or
* [advanceTimeBy], or [advanceUntilIdle] to execute coroutines.
*/
@Deprecated(
"Please use a dispatcher that is paused by default, like `StandardTestDispatcher`.",
level = DeprecationLevel.WARNING
)
@ExperimentalCoroutinesApi // Since 1.2.1, tentatively till 1.3.0
public fun pauseDispatcher()

Expand All @@ -119,6 +127,10 @@ public interface DelayController {
* time and execute coroutines scheduled in the future use, one of [advanceTimeBy],
* or [advanceUntilIdle].
*/
@Deprecated(
"Please use a dispatcher that is paused by default, like `StandardTestDispatcher`.",
level = DeprecationLevel.WARNING
)
@ExperimentalCoroutinesApi // Since 1.2.1, tentatively till 1.3.0
public fun resumeDispatcher()
}
Expand Down
3 changes: 3 additions & 0 deletions kotlinx-coroutines-test/common/src/TestCoroutineDispatcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import kotlin.coroutines.*
* @see DelayController
*/
@ExperimentalCoroutinesApi // Since 1.2.1, tentatively till 1.3.0
@Deprecated("The execution order of `TestCoroutineDispatcher` can be confusing, and the mechanism of " +
"pausing is typically misunderstood. Please use `StandardTestDispatcher` or `UnconfinedTestDispatcher` instead.",
level = DeprecationLevel.WARNING)
public class TestCoroutineDispatcher(public override val scheduler: TestCoroutineScheduler = TestCoroutineScheduler()):
TestDispatcher(), Delay, SchedulerAsDelayController
{
Expand Down

0 comments on commit d1c2768

Please sign in to comment.