getPolymorphicElement
fun <E : CoroutineContext.Element> CoroutineContext.Element.getPolymorphicElement(key: CoroutineContext.Key<E>): E?(source)
Deprecated
Warning since 2.4
Polymorphic coroutine context keys are error-prone, difficult to implement correctly, and can encourage depending on implementation details. Prefer retrieving the element by its base key and casting it explicitly when needed or introducing a dedicated extension property.
Returns the current element if it is associated with the given key in a polymorphic manner or null otherwise. This method returns non-null value if either Element.key is equal to the given key or if the key is associated with Element.key via AbstractCoroutineContextKey. See AbstractCoroutineContextKey for the example of usage.