Closed
Description
The closest equivalent to the JVM's Thread.currentThread()
for coroutines is
coroutineContext[Job]!!
This !!
cast always succeeds, but it draws the developer's attention and brings in uncertainty about the correctness of the code. Here's an example where this concern was raised on Stack Overflow.
Kotlin could provide a function that hides this check, for example:
suspend fun currentJob(): Job = coroutineContext[Job]!!
Originally reported here