You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
This has the same problem as cancel() and isActive: once we have a suspending variant, it's also convenient to provide extension on CoroutineScope and that's where things go wild:
runBlocking {
flow {
currentJob() // <- resolves into extension on `runBlocking` instead of suspending variant
}.collect().launchIn(Job())
}
@qwwdfsad I think to avoid confusion/conflicts, the CoroutineScope extension currentJob() will need to be a different name than the suspending version. How about currentScopeJob()?
The closest equivalent to the JVM's
Thread.currentThread()
for coroutines isThis
!!
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:
Originally reported here
The text was updated successfully, but these errors were encountered: