isPresent

inline suspend fun ThreadLocal<*>.isPresent(): Boolean

Return true when current thread local is present in the coroutine context, false otherwise. Thread local can be present in the context only if it was added via asContextElement to the context.

Example of usage:

suspend fun processRequest() {
if (traceCurrentRequestThreadLocal.isPresent()) { // Probabilistic tracing
// Do some heavy-weight tracing
}
// Process request regularly
}

Sources

jvm source
Link copied to clipboard