• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 package kotlin.coroutines
5 
6 // DOKKA STUB
7 public interface CoroutineContext {
getnull8     public operator fun <E : Element> get(key: Key<E>): E?
9     public fun <R> fold(initial: R, operation: (R, Element) -> R): R
10     public operator fun plus(context: CoroutineContext): CoroutineContext = TODO()
11     public fun minusKey(key: Key<*>): CoroutineContext
12     public interface Key<E : Element>
13     public interface Element : CoroutineContext {
14         public val key: Key<*>
15 
16         public override operator fun <E : Element> get(key: Key<E>): E? =
17             @Suppress("UNCHECKED_CAST")
18             if (this.key == key) this as E else null
19 
20         public override fun <R> fold(initial: R, operation: (R, Element) -> R): R =
21             operation(initial, this)
22 
23         public override fun minusKey(key: Key<*>): CoroutineContext =
24             if (this.key == key) EmptyCoroutineContext else this
25     }
26 }
27 
28 public object EmptyCoroutineContext : CoroutineContext {
29     private const val serialVersionUID: Long = 0
readResolvenull30     private fun readResolve(): Any = EmptyCoroutineContext
31 
32     public override fun <E : CoroutineContext.Element> get(key: CoroutineContext.Key<E>): E? = null
33     public override fun <R> fold(initial: R, operation: (R, CoroutineContext.Element) -> R): R = initial
34     public override fun plus(context: CoroutineContext): CoroutineContext = context
35     public override fun minusKey(key: CoroutineContext.Key<*>): CoroutineContext = this
36     public override fun hashCode(): Int = 0
37     public override fun toString(): String = "EmptyCoroutineContext"
38 }
39