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:
Roman Elizarov
2017-01-16 10:01:02 +03:00
parent ea7fac07c4
commit 25739a08ea
11 changed files with 98 additions and 118 deletions
+1 -6
View File
@@ -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>(
@@ -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>(