CoroutineContext Key and Element are now inside CoroutineContext interface itself (just like Map.Entry)
ContinuationInterceptor companion object is named Key CoroutineContext.Element property for key is named just key AbstractCoroutineContextElement implements all of CoroutineContext.Element, including key
This commit is contained in:
+21
-21
@@ -7,37 +7,37 @@ package-fragment kotlin.coroutines
|
||||
public abstract fun resumeWithException(/*0*/ exception: kotlin.Throwable): kotlin.Unit
|
||||
}
|
||||
|
||||
@kotlin.SinceKotlin(version = "1.1") public interface ContinuationInterceptor : kotlin.coroutines.CoroutineContextElement {
|
||||
public abstract override /*1*/ /*fake_override*/ val contextKey: kotlin.coroutines.CoroutineContextKey<*>
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-contextKey>(): kotlin.coroutines.CoroutineContextKey<*>
|
||||
public abstract override /*1*/ /*fake_override*/ fun </*0*/ R> fold(/*0*/ initial: R, /*1*/ operation: (R, kotlin.coroutines.CoroutineContextElement) -> R): R
|
||||
public abstract override /*1*/ /*fake_override*/ fun </*0*/ E : kotlin.coroutines.CoroutineContextElement> get(/*0*/ key: kotlin.coroutines.CoroutineContextKey<E>): E?
|
||||
@kotlin.SinceKotlin(version = "1.1") public interface ContinuationInterceptor : kotlin.coroutines.CoroutineContext.Element {
|
||||
public abstract override /*1*/ /*fake_override*/ val key: kotlin.coroutines.CoroutineContext.Key<*>
|
||||
public abstract override /*1*/ /*fake_override*/ fun <get-key>(): kotlin.coroutines.CoroutineContext.Key<*>
|
||||
public abstract override /*1*/ /*fake_override*/ fun </*0*/ R> fold(/*0*/ initial: R, /*1*/ operation: (R, kotlin.coroutines.CoroutineContext.Element) -> R): R
|
||||
public abstract override /*1*/ /*fake_override*/ fun </*0*/ E : kotlin.coroutines.CoroutineContext.Element> get(/*0*/ key: kotlin.coroutines.CoroutineContext.Key<E>): E?
|
||||
public abstract fun </*0*/ T> interceptContinuation(/*0*/ continuation: kotlin.coroutines.Continuation<T>): kotlin.coroutines.Continuation<T>
|
||||
public abstract override /*1*/ /*fake_override*/ fun minusKey(/*0*/ key: kotlin.coroutines.CoroutineContextKey<*>): kotlin.coroutines.CoroutineContext
|
||||
public abstract override /*1*/ /*fake_override*/ fun minusKey(/*0*/ key: kotlin.coroutines.CoroutineContext.Key<*>): kotlin.coroutines.CoroutineContext
|
||||
public abstract override /*1*/ /*fake_override*/ fun plus(/*0*/ context: kotlin.coroutines.CoroutineContext): kotlin.coroutines.CoroutineContext
|
||||
|
||||
public companion object Companion : kotlin.coroutines.CoroutineContextKey<kotlin.coroutines.ContinuationInterceptor> {
|
||||
/*primary*/ private constructor Companion()
|
||||
public companion object Key : kotlin.coroutines.CoroutineContext.Key<kotlin.coroutines.ContinuationInterceptor> {
|
||||
/*primary*/ private constructor Key()
|
||||
}
|
||||
}
|
||||
|
||||
@kotlin.SinceKotlin(version = "1.1") public interface CoroutineContext {
|
||||
public abstract fun </*0*/ R> fold(/*0*/ initial: R, /*1*/ operation: (R, kotlin.coroutines.CoroutineContextElement) -> R): R
|
||||
public abstract operator fun </*0*/ E : kotlin.coroutines.CoroutineContextElement> get(/*0*/ key: kotlin.coroutines.CoroutineContextKey<E>): E?
|
||||
public abstract fun minusKey(/*0*/ key: kotlin.coroutines.CoroutineContextKey<*>): kotlin.coroutines.CoroutineContext
|
||||
public abstract fun </*0*/ R> fold(/*0*/ initial: R, /*1*/ operation: (R, kotlin.coroutines.CoroutineContext.Element) -> R): R
|
||||
public abstract operator fun </*0*/ E : kotlin.coroutines.CoroutineContext.Element> get(/*0*/ key: kotlin.coroutines.CoroutineContext.Key<E>): E?
|
||||
public abstract fun minusKey(/*0*/ key: kotlin.coroutines.CoroutineContext.Key<*>): kotlin.coroutines.CoroutineContext
|
||||
public abstract operator fun plus(/*0*/ context: kotlin.coroutines.CoroutineContext): kotlin.coroutines.CoroutineContext
|
||||
}
|
||||
|
||||
@kotlin.SinceKotlin(version = "1.1") public interface CoroutineContextElement : kotlin.coroutines.CoroutineContext {
|
||||
public abstract val contextKey: kotlin.coroutines.CoroutineContextKey<*>
|
||||
public abstract fun <get-contextKey>(): kotlin.coroutines.CoroutineContextKey<*>
|
||||
public abstract override /*1*/ /*fake_override*/ fun </*0*/ R> fold(/*0*/ initial: R, /*1*/ operation: (R, kotlin.coroutines.CoroutineContextElement) -> R): R
|
||||
public abstract override /*1*/ /*fake_override*/ fun </*0*/ E : kotlin.coroutines.CoroutineContextElement> get(/*0*/ key: kotlin.coroutines.CoroutineContextKey<E>): E?
|
||||
public abstract override /*1*/ /*fake_override*/ fun minusKey(/*0*/ key: kotlin.coroutines.CoroutineContextKey<*>): kotlin.coroutines.CoroutineContext
|
||||
public abstract override /*1*/ /*fake_override*/ fun plus(/*0*/ context: kotlin.coroutines.CoroutineContext): kotlin.coroutines.CoroutineContext
|
||||
}
|
||||
public interface Element : kotlin.coroutines.CoroutineContext {
|
||||
public abstract val key: kotlin.coroutines.CoroutineContext.Key<*>
|
||||
public abstract fun <get-key>(): kotlin.coroutines.CoroutineContext.Key<*>
|
||||
public abstract override /*1*/ /*fake_override*/ fun </*0*/ R> fold(/*0*/ initial: R, /*1*/ operation: (R, kotlin.coroutines.CoroutineContext.Element) -> R): R
|
||||
public abstract override /*1*/ /*fake_override*/ fun </*0*/ E : kotlin.coroutines.CoroutineContext.Element> get(/*0*/ key: kotlin.coroutines.CoroutineContext.Key<E>): E?
|
||||
public abstract override /*1*/ /*fake_override*/ fun minusKey(/*0*/ key: kotlin.coroutines.CoroutineContext.Key<*>): kotlin.coroutines.CoroutineContext
|
||||
public abstract override /*1*/ /*fake_override*/ fun plus(/*0*/ context: kotlin.coroutines.CoroutineContext): kotlin.coroutines.CoroutineContext
|
||||
}
|
||||
|
||||
@kotlin.SinceKotlin(version = "1.1") public interface CoroutineContextKey</*0*/ E : kotlin.coroutines.CoroutineContextElement> {
|
||||
public interface Key</*0*/ E : kotlin.coroutines.CoroutineContext.Element> {
|
||||
}
|
||||
}
|
||||
|
||||
@kotlin.SinceKotlin(version = "1.1") @kotlin.annotation.Target(allowedTargets = {AnnotationTarget.CLASS}) @kotlin.annotation.Retention(value = AnnotationRetention.BINARY) public final annotation class RestrictsSuspension : kotlin.Annotation {
|
||||
|
||||
@@ -20,15 +20,10 @@ class Controller {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class ContinuationDispatcher : ContinuationInterceptor {
|
||||
override val contextKey: CoroutineContextKey<*> = ContinuationInterceptor
|
||||
abstract class ContinuationDispatcher : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor {
|
||||
abstract fun <T> dispatchResume(value: T, continuation: Continuation<T>): Boolean
|
||||
abstract fun dispatchResumeWithException(exception: Throwable, continuation: Continuation<*>): Boolean
|
||||
override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> = DispatchedContinuation(this, continuation)
|
||||
override operator fun <E : CoroutineContextElement> get(key: CoroutineContextKey<E>): E? = if (this.contextKey == key) this as E else null
|
||||
override fun <R> fold(initial: R, operation: (R, CoroutineContextElement) -> R): R = operation(initial, this)
|
||||
override operator fun plus(context: CoroutineContext): CoroutineContext = this
|
||||
override fun minusKey(key: CoroutineContextKey<*>): CoroutineContext = if (this.contextKey == key) EmptyCoroutineContext else this
|
||||
}
|
||||
|
||||
private class DispatchedContinuation<T>(
|
||||
|
||||
+1
-6
@@ -21,15 +21,10 @@ class Controller {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class ContinuationDispatcher : ContinuationInterceptor {
|
||||
override val contextKey: CoroutineContextKey<*> = ContinuationInterceptor
|
||||
abstract class ContinuationDispatcher : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor {
|
||||
abstract fun <T> dispatchResume(value: T, continuation: Continuation<T>): Boolean
|
||||
abstract fun dispatchResumeWithException(exception: Throwable, continuation: Continuation<*>): Boolean
|
||||
override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> = DispatchedContinuation(this, continuation)
|
||||
override operator fun <E : CoroutineContextElement> get(key: CoroutineContextKey<E>): E? = if (this.contextKey == key) this as E else null
|
||||
override fun <R> fold(initial: R, operation: (R, CoroutineContextElement) -> R): R = operation(initial, this)
|
||||
override operator fun plus(context: CoroutineContext): CoroutineContext = this
|
||||
override fun minusKey(key: CoroutineContextKey<*>): CoroutineContext = if (this.contextKey == key) EmptyCoroutineContext else this
|
||||
}
|
||||
|
||||
private class DispatchedContinuation<T>(
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
@kotlin.Metadata
|
||||
public abstract class ContinuationDispatcher {
|
||||
private final @org.jetbrains.annotations.NotNull field contextKey: kotlin.coroutines.CoroutineContextKey
|
||||
public method <init>(): void
|
||||
public abstract method dispatchResume(p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): boolean
|
||||
public abstract method dispatchResumeWithException(@org.jetbrains.annotations.NotNull p0: java.lang.Throwable, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): boolean
|
||||
public method fold(p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.jvm.functions.Function2): java.lang.Object
|
||||
public @org.jetbrains.annotations.Nullable method get(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.CoroutineContextKey): kotlin.coroutines.CoroutineContextElement
|
||||
public @org.jetbrains.annotations.NotNull method getContextKey(): kotlin.coroutines.CoroutineContextKey
|
||||
public @org.jetbrains.annotations.NotNull method interceptContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation
|
||||
public @org.jetbrains.annotations.NotNull method minusKey(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.CoroutineContextKey): kotlin.coroutines.CoroutineContext
|
||||
public @org.jetbrains.annotations.NotNull method plus(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.CoroutineContext): kotlin.coroutines.CoroutineContext
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
|
||||
Vendored
-6
@@ -1,15 +1,9 @@
|
||||
@kotlin.Metadata
|
||||
public abstract class ContinuationDispatcher {
|
||||
private final @org.jetbrains.annotations.NotNull field contextKey: kotlin.coroutines.CoroutineContextKey
|
||||
public method <init>(): void
|
||||
public abstract method dispatchResume(p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): boolean
|
||||
public abstract method dispatchResumeWithException(@org.jetbrains.annotations.NotNull p0: java.lang.Throwable, @org.jetbrains.annotations.NotNull p1: kotlin.coroutines.Continuation): boolean
|
||||
public method fold(p0: java.lang.Object, @org.jetbrains.annotations.NotNull p1: kotlin.jvm.functions.Function2): java.lang.Object
|
||||
public @org.jetbrains.annotations.Nullable method get(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.CoroutineContextKey): kotlin.coroutines.CoroutineContextElement
|
||||
public @org.jetbrains.annotations.NotNull method getContextKey(): kotlin.coroutines.CoroutineContextKey
|
||||
public @org.jetbrains.annotations.NotNull method interceptContinuation(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.Continuation): kotlin.coroutines.Continuation
|
||||
public @org.jetbrains.annotations.NotNull method minusKey(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.CoroutineContextKey): kotlin.coroutines.CoroutineContext
|
||||
public @org.jetbrains.annotations.NotNull method plus(@org.jetbrains.annotations.NotNull p0: kotlin.coroutines.CoroutineContext): kotlin.coroutines.CoroutineContext
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
|
||||
@@ -18,17 +18,24 @@ package kotlin.coroutines
|
||||
|
||||
/**
|
||||
* Marks coroutine context element that intercepts coroutine continuations.
|
||||
* The coroutines framework uses [ContinuationInterceptor.Key] to retrieve the interceptor and
|
||||
* intercepts all coroutine continuations with [interceptContinuation] invocations.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public interface ContinuationInterceptor : CoroutineContextElement {
|
||||
public interface ContinuationInterceptor : CoroutineContext.Element {
|
||||
/**
|
||||
* The key that defines *the* context interceptor.
|
||||
*/
|
||||
companion object : CoroutineContextKey<ContinuationInterceptor>
|
||||
companion object Key : CoroutineContext.Key<ContinuationInterceptor>
|
||||
|
||||
/**
|
||||
* Intercepts the given [continuation] by wrapping it. Application code should not call this method directly as
|
||||
* it is invoked by coroutines framework appropriately and the resulting continuations are efficiently cached.
|
||||
* Returns continuation that wraps the original [continuation], thus intercepting all resumptions.
|
||||
* This function is invoked by coroutines framework when needed and the resulting continuations are
|
||||
* cached internally per each instance of the original [continuation].
|
||||
*
|
||||
* By convention, implementations that install themselves as *the* interceptor in the context with
|
||||
* the [Key] shall also scan the context for other element that implement [ContinuationInterceptor] interface
|
||||
* and use their [interceptContinuation] functions, too.
|
||||
*/
|
||||
public fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T>
|
||||
}
|
||||
|
||||
@@ -17,25 +17,25 @@
|
||||
package kotlin.coroutines
|
||||
|
||||
/**
|
||||
* Persistent context for the coroutine. It is an indexed set of [CoroutineContextElement] instances.
|
||||
* Persistent context for the coroutine. It is an indexed set of [Element] instances.
|
||||
* An indexed set is a mix between a set and a map.
|
||||
* Every element in this set has a unique [CoroutineContextKey].
|
||||
* Every element in this set has a unique [Key].
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public interface CoroutineContext {
|
||||
/**
|
||||
* Returns an element with the given [key] in this context or `null`.
|
||||
* Returns the element with the given [key] from this context or `null`.
|
||||
*/
|
||||
public operator fun <E : CoroutineContextElement> get(key: CoroutineContextKey<E>): E?
|
||||
public operator fun <E : Element> get(key: Key<E>): E?
|
||||
|
||||
/**
|
||||
* Accumulates entries of this context starting with [initial] value and applying [operation]
|
||||
* from left to right to current accumulator value and each element of this context.
|
||||
*/
|
||||
public fun <R> fold(initial: R, operation: (R, CoroutineContextElement) -> R): R
|
||||
public fun <R> fold(initial: R, operation: (R, Element) -> R): R
|
||||
|
||||
/**
|
||||
* Returns a context containing elements from this context and elements from other [context].
|
||||
* Returns a context containing elements from this context and elements from other [context].
|
||||
* The elements from this context with the same key as in the other one are dropped.
|
||||
*/
|
||||
public operator fun plus(context: CoroutineContext): CoroutineContext
|
||||
@@ -44,23 +44,20 @@ public interface CoroutineContext {
|
||||
* Returns a context containing elements from this context, but without an element with
|
||||
* the specified [key].
|
||||
*/
|
||||
public fun minusKey(key: CoroutineContextKey<*>): CoroutineContext
|
||||
}
|
||||
public fun minusKey(key: Key<*>): CoroutineContext
|
||||
|
||||
/**
|
||||
* An element of the [CoroutineContext]. An element of the coroutine context is a singleton context by itself.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public interface CoroutineContextElement : CoroutineContext {
|
||||
/**
|
||||
* A key of this coroutine context element.
|
||||
* An element of the [CoroutineContext]. An element of the coroutine context is a singleton context by itself.
|
||||
*/
|
||||
public val contextKey: CoroutineContextKey<*>
|
||||
public interface Element : CoroutineContext {
|
||||
/**
|
||||
* A key of this coroutine context element.
|
||||
*/
|
||||
public val key: Key<*>
|
||||
}
|
||||
|
||||
/**
|
||||
* Key for the elements of [CoroutineContext]. [E] is a type of element with this key.
|
||||
*/
|
||||
public interface Key<E : Element>
|
||||
}
|
||||
|
||||
/**
|
||||
* Key for the elements of [CoroutineContext]. [E] is a type of the element with this key.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public interface CoroutineContextKey<E : CoroutineContextElement>
|
||||
|
||||
|
||||
@@ -16,23 +16,25 @@
|
||||
|
||||
package kotlin.coroutines
|
||||
|
||||
import kotlin.coroutines.CoroutineContext.*
|
||||
|
||||
/**
|
||||
* Base class for [CoroutineContextElement] implementations.
|
||||
* Base class for [CoroutineContext.Element] implementations.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public abstract class AbstractCoroutineContextElement : CoroutineContextElement {
|
||||
public abstract class AbstractCoroutineContextElement(public override val key: Key<*>) : Element {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public override operator fun <E : CoroutineContextElement> get(key: CoroutineContextKey<E>): E? =
|
||||
if (this.contextKey == key) this as E else null
|
||||
public override operator fun <E : Element> get(key: Key<E>): E? =
|
||||
if (this.key == key) this as E else null
|
||||
|
||||
public override fun <R> fold(initial: R, operation: (R, CoroutineContextElement) -> R): R =
|
||||
public override fun <R> fold(initial: R, operation: (R, Element) -> R): R =
|
||||
operation(initial, this)
|
||||
|
||||
public override operator fun plus(context: CoroutineContext): CoroutineContext =
|
||||
plusImpl(context)
|
||||
|
||||
public override fun minusKey(key: CoroutineContextKey<*>): CoroutineContext =
|
||||
if (this.contextKey == key) EmptyCoroutineContext else this
|
||||
public override fun minusKey(key: Key<*>): CoroutineContext =
|
||||
if (this.key == key) EmptyCoroutineContext else this
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,10 +42,10 @@ public abstract class AbstractCoroutineContextElement : CoroutineContextElement
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
public object EmptyCoroutineContext : CoroutineContext {
|
||||
public override fun <E : CoroutineContextElement> get(key: CoroutineContextKey<E>): E? = null
|
||||
public override fun <R> fold(initial: R, operation: (R, CoroutineContextElement) -> R): R = initial
|
||||
public override fun <E : Element> get(key: Key<E>): E? = null
|
||||
public override fun <R> fold(initial: R, operation: (R, Element) -> R): R = initial
|
||||
public override fun plus(context: CoroutineContext): CoroutineContext = context
|
||||
public override fun minusKey(key: CoroutineContextKey<*>): CoroutineContext = this
|
||||
public override fun minusKey(key: Key<*>): CoroutineContext = this
|
||||
public override fun hashCode(): Int = 0
|
||||
public override fun toString(): String = "EmptyCoroutineContext"
|
||||
}
|
||||
@@ -52,8 +54,8 @@ public object EmptyCoroutineContext : CoroutineContext {
|
||||
|
||||
// this class is not exposed, but is hidden inside implementations
|
||||
// this is a left-biased list, so that `plus` works naturally
|
||||
private class CombinedContext(val left: CoroutineContext, val element: CoroutineContextElement) : CoroutineContext {
|
||||
override fun <E : CoroutineContextElement> get(key: CoroutineContextKey<E>): E? {
|
||||
private class CombinedContext(val left: CoroutineContext, val element: Element) : CoroutineContext {
|
||||
override fun <E : Element> get(key: Key<E>): E? {
|
||||
var cur = this
|
||||
while (true) {
|
||||
cur.element[key]?.let { return it }
|
||||
@@ -66,13 +68,13 @@ private class CombinedContext(val left: CoroutineContext, val element: Coroutine
|
||||
}
|
||||
}
|
||||
|
||||
public override fun <R> fold(initial: R, operation: (R, CoroutineContextElement) -> R): R =
|
||||
public override fun <R> fold(initial: R, operation: (R, Element) -> R): R =
|
||||
operation(left.fold(initial, operation), element)
|
||||
|
||||
public override operator fun plus(context: CoroutineContext): CoroutineContext =
|
||||
plusImpl(context)
|
||||
|
||||
public override fun minusKey(key: CoroutineContextKey<*>): CoroutineContext {
|
||||
public override fun minusKey(key: Key<*>): CoroutineContext {
|
||||
element[key]?.let { return left }
|
||||
val newLeft = left.minusKey(key)
|
||||
return when (newLeft) {
|
||||
@@ -85,8 +87,8 @@ private class CombinedContext(val left: CoroutineContext, val element: Coroutine
|
||||
private fun size(): Int =
|
||||
if (left is CombinedContext) left.size() + 1 else 2
|
||||
|
||||
private fun contains(element: CoroutineContextElement): Boolean =
|
||||
get(element.contextKey) == element
|
||||
private fun contains(element: Element): Boolean =
|
||||
get(element.key) == element
|
||||
|
||||
private fun containsAll(context: CombinedContext): Boolean {
|
||||
var cur = context
|
||||
@@ -96,7 +98,7 @@ private class CombinedContext(val left: CoroutineContext, val element: Coroutine
|
||||
if (next is CombinedContext) {
|
||||
cur = next
|
||||
} else {
|
||||
return contains(next as CoroutineContextElement)
|
||||
return contains(next as Element)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,7 +117,7 @@ private class CombinedContext(val left: CoroutineContext, val element: Coroutine
|
||||
private fun CoroutineContext.plusImpl(context: CoroutineContext): CoroutineContext =
|
||||
if (context == EmptyCoroutineContext) this else // fast path -- avoid lambda creation
|
||||
context.fold(this) { acc, element ->
|
||||
val removed = acc.minusKey(element.contextKey)
|
||||
val removed = acc.minusKey(element.key)
|
||||
if (removed == EmptyCoroutineContext) element else {
|
||||
// make sure interceptor is always last in the context (and thus is fast to get when present)
|
||||
val interceptor = removed[ContinuationInterceptor]
|
||||
|
||||
@@ -21,30 +21,25 @@ import org.junit.Test
|
||||
import kotlin.coroutines.*
|
||||
|
||||
class CoroutineContextTest {
|
||||
data class CtxA(val i: Int) : AbstractCoroutineContextElement() {
|
||||
companion object : CoroutineContextKey<CtxA>
|
||||
override val contextKey get() = CtxA
|
||||
data class CtxA(val i: Int) : AbstractCoroutineContextElement(CtxA) {
|
||||
companion object Key : CoroutineContext.Key<CtxA>
|
||||
}
|
||||
|
||||
data class CtxB(val i: Int) : AbstractCoroutineContextElement() {
|
||||
companion object : CoroutineContextKey<CtxB>
|
||||
override val contextKey get() = CtxB
|
||||
data class CtxB(val i: Int) : AbstractCoroutineContextElement(CtxB) {
|
||||
companion object Key : CoroutineContext.Key<CtxB>
|
||||
}
|
||||
|
||||
data class CtxC(val i: Int) : AbstractCoroutineContextElement() {
|
||||
companion object : CoroutineContextKey<CtxC>
|
||||
override val contextKey get() = CtxC
|
||||
data class CtxC(val i: Int) : AbstractCoroutineContextElement(CtxC) {
|
||||
companion object Key : CoroutineContext.Key<CtxC>
|
||||
}
|
||||
|
||||
object Disp1 : AbstractCoroutineContextElement(), ContinuationInterceptor {
|
||||
object Disp1 : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor {
|
||||
override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> = continuation
|
||||
override val contextKey: CoroutineContextKey<*> = ContinuationInterceptor
|
||||
override fun toString(): String = "Disp1"
|
||||
}
|
||||
|
||||
object Disp2 : AbstractCoroutineContextElement(), ContinuationInterceptor {
|
||||
object Disp2 : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor {
|
||||
override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> = continuation
|
||||
override val contextKey: CoroutineContextKey<*> = ContinuationInterceptor
|
||||
override fun toString(): String = "Disp2"
|
||||
}
|
||||
|
||||
@@ -171,10 +166,10 @@ class CoroutineContextTest {
|
||||
assertNotEquals(ctx3, ctx4)
|
||||
}
|
||||
|
||||
private fun assertContents(ctx: CoroutineContext, vararg elements: CoroutineContextElement) {
|
||||
private fun assertContents(ctx: CoroutineContext, vararg elements: CoroutineContext.Element) {
|
||||
val set = ctx.fold(setOf<CoroutineContext>()) { a, b -> a + b }
|
||||
assertEquals(listOf(*elements), set.toList())
|
||||
for (elem in elements)
|
||||
assertTrue(ctx[elem.contextKey] == elem)
|
||||
assertTrue(ctx[elem.key] == elem)
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -185,26 +185,26 @@ public abstract interface class kotlin/coroutines/Continuation {
|
||||
public abstract fun resumeWithException (Ljava/lang/Throwable;)V
|
||||
}
|
||||
|
||||
public abstract interface class kotlin/coroutines/ContinuationInterceptor : kotlin/coroutines/CoroutineContextElement {
|
||||
public static final field Companion Lkotlin/coroutines/ContinuationInterceptor$Companion;
|
||||
public abstract interface class kotlin/coroutines/ContinuationInterceptor : kotlin/coroutines/CoroutineContext$Element {
|
||||
public static final field Key Lkotlin/coroutines/ContinuationInterceptor$Key;
|
||||
public abstract fun interceptContinuation (Lkotlin/coroutines/Continuation;)Lkotlin/coroutines/Continuation;
|
||||
}
|
||||
|
||||
public final class kotlin/coroutines/ContinuationInterceptor$Companion : kotlin/coroutines/CoroutineContextKey {
|
||||
public final class kotlin/coroutines/ContinuationInterceptor$Key : kotlin/coroutines/CoroutineContext$Key {
|
||||
}
|
||||
|
||||
public abstract interface class kotlin/coroutines/CoroutineContext {
|
||||
public abstract fun fold (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object;
|
||||
public abstract fun get (Lkotlin/coroutines/CoroutineContextKey;)Lkotlin/coroutines/CoroutineContextElement;
|
||||
public abstract fun minusKey (Lkotlin/coroutines/CoroutineContextKey;)Lkotlin/coroutines/CoroutineContext;
|
||||
public abstract fun get (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext$Element;
|
||||
public abstract fun minusKey (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext;
|
||||
public abstract fun plus (Lkotlin/coroutines/CoroutineContext;)Lkotlin/coroutines/CoroutineContext;
|
||||
}
|
||||
|
||||
public abstract interface class kotlin/coroutines/CoroutineContextElement : kotlin/coroutines/CoroutineContext {
|
||||
public abstract fun getContextKey ()Lkotlin/coroutines/CoroutineContextKey;
|
||||
public abstract interface class kotlin/coroutines/CoroutineContext$Element : kotlin/coroutines/CoroutineContext {
|
||||
public abstract fun getKey ()Lkotlin/coroutines/CoroutineContext$Key;
|
||||
}
|
||||
|
||||
public abstract interface class kotlin/coroutines/CoroutineContextKey {
|
||||
public abstract interface class kotlin/coroutines/CoroutineContext$Key {
|
||||
}
|
||||
|
||||
public abstract interface annotation class kotlin/coroutines/RestrictsSuspension : java/lang/annotation/Annotation {
|
||||
|
||||
+7
-6
@@ -1754,11 +1754,12 @@ public final class kotlin/concurrent/TimersKt {
|
||||
public static final fun timer (Ljava/lang/String;Z)Ljava/util/Timer;
|
||||
}
|
||||
|
||||
public abstract class kotlin/coroutines/AbstractCoroutineContextElement : kotlin/coroutines/CoroutineContextElement {
|
||||
public fun <init> ()V
|
||||
public abstract class kotlin/coroutines/AbstractCoroutineContextElement : kotlin/coroutines/CoroutineContext$Element {
|
||||
public fun <init> (Lkotlin/coroutines/CoroutineContext$Key;)V
|
||||
public fun fold (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object;
|
||||
public fun get (Lkotlin/coroutines/CoroutineContextKey;)Lkotlin/coroutines/CoroutineContextElement;
|
||||
public fun minusKey (Lkotlin/coroutines/CoroutineContextKey;)Lkotlin/coroutines/CoroutineContext;
|
||||
public fun get (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext$Element;
|
||||
public fun getKey ()Lkotlin/coroutines/CoroutineContext$Key;
|
||||
public fun minusKey (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext;
|
||||
public fun plus (Lkotlin/coroutines/CoroutineContext;)Lkotlin/coroutines/CoroutineContext;
|
||||
}
|
||||
|
||||
@@ -1773,9 +1774,9 @@ public final class kotlin/coroutines/CoroutinesKt {
|
||||
public final class kotlin/coroutines/EmptyCoroutineContext : kotlin/coroutines/CoroutineContext {
|
||||
public static final field INSTANCE Lkotlin/coroutines/EmptyCoroutineContext;
|
||||
public fun fold (Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object;
|
||||
public fun get (Lkotlin/coroutines/CoroutineContextKey;)Lkotlin/coroutines/CoroutineContextElement;
|
||||
public fun get (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext$Element;
|
||||
public fun hashCode ()I
|
||||
public fun minusKey (Lkotlin/coroutines/CoroutineContextKey;)Lkotlin/coroutines/CoroutineContext;
|
||||
public fun minusKey (Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext;
|
||||
public fun plus (Lkotlin/coroutines/CoroutineContext;)Lkotlin/coroutines/CoroutineContext;
|
||||
public fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user