Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhalanskyjb committed Nov 1, 2021
1 parent f087205 commit 6a33516
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 55 deletions.
9 changes: 9 additions & 0 deletions kotlinx-coroutines-core/api/kotlinx-coroutines-core.api
Expand Up @@ -545,6 +545,15 @@ public final class kotlinx/coroutines/TimeoutKt {
public static final fun withTimeoutOrNull-KLykuaI (JLkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class kotlinx/coroutines/YieldContext : kotlin/coroutines/AbstractCoroutineContextElement {
public static final field Key Lkotlinx/coroutines/YieldContext$Key;
public field dispatcherWasUnconfined Z
public fun <init> ()V
}

public final class kotlinx/coroutines/YieldContext$Key : kotlin/coroutines/CoroutineContext$Key {
}

public final class kotlinx/coroutines/YieldKt {
public static final fun yield (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
Expand Down
1 change: 1 addition & 0 deletions kotlinx-coroutines-core/common/src/Unconfined.kt
Expand Up @@ -38,6 +38,7 @@ internal object Unconfined : CoroutineDispatcher() {
/**
* Used to detect calls to [Unconfined.dispatch] from [yield] function.
*/
@PublishedApi
internal class YieldContext : AbstractCoroutineContextElement(Key) {
companion object Key : CoroutineContext.Key<YieldContext>

Expand Down
27 changes: 7 additions & 20 deletions kotlinx-coroutines-test/api/kotlinx-coroutines-test.api
Expand Up @@ -9,15 +9,6 @@ public abstract interface class kotlinx/coroutines/test/DelayController {
public abstract fun runCurrent ()V
}

public final class kotlinx/coroutines/test/StandardTestDispatcher : kotlinx/coroutines/test/TestDispatcher, kotlinx/coroutines/Delay {
public fun <init> ()V
public fun <init> (Lkotlinx/coroutines/test/TestCoroutineScheduler;Ljava/lang/String;)V
public synthetic fun <init> (Lkotlinx/coroutines/test/TestCoroutineScheduler;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun dispatch (Lkotlin/coroutines/CoroutineContext;Ljava/lang/Runnable;)V
public fun getScheduler ()Lkotlinx/coroutines/test/TestCoroutineScheduler;
public fun toString ()Ljava/lang/String;
}

public final class kotlinx/coroutines/test/TestBuildersKt {
public static final fun runBlockingTest (Lkotlin/coroutines/CoroutineContext;Lkotlin/jvm/functions/Function2;)V
public static final fun runBlockingTest (Lkotlinx/coroutines/test/TestCoroutineDispatcher;Lkotlin/jvm/functions/Function2;)V
Expand Down Expand Up @@ -49,6 +40,13 @@ public final class kotlinx/coroutines/test/TestCoroutineDispatcher : kotlinx/cor
public fun toString ()Ljava/lang/String;
}

public final class kotlinx/coroutines/test/TestCoroutineDispatchersKt {
public static final fun StandardTestDispatcher (Lkotlinx/coroutines/test/TestCoroutineScheduler;Ljava/lang/String;)Lkotlinx/coroutines/test/TestDispatcher;
public static synthetic fun StandardTestDispatcher$default (Lkotlinx/coroutines/test/TestCoroutineScheduler;Ljava/lang/String;ILjava/lang/Object;)Lkotlinx/coroutines/test/TestDispatcher;
public static final fun UnconfinedTestDispatcher (Lkotlinx/coroutines/test/TestCoroutineScheduler;Ljava/lang/String;)Lkotlinx/coroutines/test/TestDispatcher;
public static synthetic fun UnconfinedTestDispatcher$default (Lkotlinx/coroutines/test/TestCoroutineScheduler;Ljava/lang/String;ILjava/lang/Object;)Lkotlinx/coroutines/test/TestDispatcher;
}

public final class kotlinx/coroutines/test/TestCoroutineExceptionHandler : kotlin/coroutines/AbstractCoroutineContextElement, kotlinx/coroutines/CoroutineExceptionHandler, kotlinx/coroutines/test/UncaughtExceptionCaptor {
public fun <init> ()V
public fun cleanupTestCoroutinesCaptor ()V
Expand Down Expand Up @@ -88,7 +86,6 @@ public final class kotlinx/coroutines/test/TestCoroutineScopeKt {
}

public abstract class kotlinx/coroutines/test/TestDispatcher : kotlinx/coroutines/CoroutineDispatcher, kotlinx/coroutines/Delay {
public fun <init> ()V
public fun delay (JLkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun getScheduler ()Lkotlinx/coroutines/test/TestCoroutineScheduler;
public fun invokeOnTimeout (JLjava/lang/Runnable;Lkotlin/coroutines/CoroutineContext;)Lkotlinx/coroutines/DisposableHandle;
Expand All @@ -105,13 +102,3 @@ public abstract interface class kotlinx/coroutines/test/UncaughtExceptionCaptor
public abstract fun getUncaughtExceptions ()Ljava/util/List;
}

public final class kotlinx/coroutines/test/UnconfinedTestDispatcher : kotlinx/coroutines/test/TestDispatcher, kotlinx/coroutines/Delay {
public fun <init> ()V
public fun <init> (Lkotlinx/coroutines/test/TestCoroutineScheduler;Ljava/lang/String;)V
public synthetic fun <init> (Lkotlinx/coroutines/test/TestCoroutineScheduler;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun dispatch (Lkotlin/coroutines/CoroutineContext;Ljava/lang/Runnable;)V
public fun getScheduler ()Lkotlinx/coroutines/test/TestCoroutineScheduler;
public fun isDispatchNeeded (Lkotlin/coroutines/CoroutineContext;)Z
public fun toString ()Ljava/lang/String;
}

6 changes: 0 additions & 6 deletions kotlinx-coroutines-test/common/src/TestCoroutineDispatcher.kt
Expand Up @@ -36,12 +36,6 @@ public class TestCoroutineDispatcher(public override val scheduler: TestCoroutin
}
}

/** @suppress */
override fun processEvent(time: Long, marker: Any) {
check(marker is Runnable)
marker.run()
}

/** @suppress */
override fun dispatch(context: CoroutineContext, block: Runnable) {
checkSchedulerInContext(scheduler, context)
Expand Down
46 changes: 19 additions & 27 deletions kotlinx-coroutines-test/common/src/TestCoroutineDispatchers.kt
Expand Up @@ -29,21 +29,19 @@ import kotlin.coroutines.*
* scheduler in order for the tasks to run.
*/
@ExperimentalCoroutinesApi
public class UnconfinedTestDispatcher(
public override val scheduler: TestCoroutineScheduler = TestCoroutineScheduler(),
private val name: String? = null
): TestDispatcher(), Delay {
@Suppress("FunctionName")
public fun UnconfinedTestDispatcher(
scheduler: TestCoroutineScheduler = TestCoroutineScheduler(),
name: String? = null
): TestDispatcher = UnconfinedTestDispatcherImpl(scheduler, name)

/** @suppress */
override fun processEvent(time: Long, marker: Any) {
check(marker is Runnable)
marker.run()
}
private class UnconfinedTestDispatcherImpl(
override val scheduler: TestCoroutineScheduler,
private val name: String? = null
): TestDispatcher() {

/** @suppress */
override fun isDispatchNeeded(context: CoroutineContext): Boolean = false

/** @suppress */
@Suppress("INVISIBLE_MEMBER")
override fun dispatch(context: CoroutineContext, block: Runnable) {
checkSchedulerInContext(scheduler, context)
Expand All @@ -64,9 +62,7 @@ public class UnconfinedTestDispatcher(
)
}

/** @suppress */
override fun toString(): String = "${name ?: "UnconfinedTestDispatcher"}[scheduler=$scheduler]"

}

/**
Expand All @@ -88,26 +84,22 @@ public class UnconfinedTestDispatcher(
*
* @see UnconfinedTestDispatcher for a dispatcher that is not confined to any particular thread.
*/
@Suppress("FunctionName")
public fun StandardTestDispatcher(
scheduler: TestCoroutineScheduler = TestCoroutineScheduler(),
name: String? = null
): TestDispatcher = StandardTestDispatcherImpl(scheduler, name)

@ExperimentalCoroutinesApi
public class StandardTestDispatcher(
public override val scheduler: TestCoroutineScheduler = TestCoroutineScheduler(),
private class StandardTestDispatcherImpl(
override val scheduler: TestCoroutineScheduler = TestCoroutineScheduler(),
private val name: String? = null
): TestDispatcher(), Delay {
): TestDispatcher() {

/** @suppress */
override fun processEvent(time: Long, marker: Any) {
check(marker is Runnable)
marker.run()
}

/** @suppress */
@Suppress("INVISIBLE_MEMBER")
override fun dispatch(context: CoroutineContext, block: Runnable) {
checkSchedulerInContext(scheduler, context)
scheduler.registerEvent(this, 0, block) { false }
}

/** @suppress */
override fun toString(): String = "${name ?: "ConfinedTestDispatcher"}[scheduler=$scheduler]"

override fun toString(): String = "${name ?: "StandardTestDispatcher"}[scheduler=$scheduler]"
}
7 changes: 5 additions & 2 deletions kotlinx-coroutines-test/common/src/TestDispatcher.kt
Expand Up @@ -12,13 +12,16 @@ import kotlin.jvm.*
* A test dispatcher that can interface with a [TestCoroutineScheduler].
*/
@ExperimentalCoroutinesApi
public abstract class TestDispatcher: CoroutineDispatcher(), Delay {
public sealed class TestDispatcher: CoroutineDispatcher(), Delay {
/** The scheduler that this dispatcher is linked to. */
@ExperimentalCoroutinesApi
public abstract val scheduler: TestCoroutineScheduler

/** Notifies the dispatcher that it should process a single event marked with [marker] happening at time [time]. */
internal abstract fun processEvent(time: Long, marker: Any)
internal open fun processEvent(time: Long, marker: Any) {
check(marker is Runnable)
marker.run()
}

/** @suppress */
override fun scheduleResumeAfterDelay(timeMillis: Long, continuation: CancellableContinuation<Unit>) {
Expand Down

0 comments on commit 6a33516

Please sign in to comment.