Accessing the coroutine context without a call to suspend


#1

Hi, I’m using something like the following (based on the auth example)

class AuthUser(val name: String) : AbstractCoroutineContextElement(AuthUser) {
    companion object Key : CoroutineContext.Key<AuthUser>
}

suspend fun authenticatedUser(): String? = suspendCoroutine { cont ->
    cont.resume(cont.context[AuthUser]?.name)
}

fun main(args: Array<String>) {
    runBlocking(AuthUser("admin")) {
      println(authenticatedUser())
    }
}

to provide what I would use a thread local for in a multithread env where one task is associated to one thread and I don’t want to pass contextual information around as a parameter.
My question is: can I access the coroutine context without suspending? It seems kind of pointless, I’m just using it to get access to the context, I don’t really want to suspend.