Hi folks, there is any CoroutinesContextElement/Ke...
# coroutines
Hi folks, there is any CoroutinesContextElement/Key that says when is running inside a
You would have to check if
is an
, however that is an internal class.
you could do a horrible hack like
Copy code
runBlocking {
    	.any { it.qualifiedName == "kotlinx.coroutines.EventLoop" }
but that is fragile. it'll yield false within
runBlocking { withContext(Dispatchers.Unconfined) { } }
but you're still effectively
, for example. what are you trying to do?
I'm working with a API that is low latency dependent and there is a Server Loop, we have a couple functions that use Mutex and in some cases we need to use runBlocking, launch a coroutines is not a choose in this cases, we also have a dispatcher that dispatches to this thread in the next Server Loop, the problem is when: we are on the Main Thread and we are using a runBlocking and some code tries to switch to this Main Thread Dispatcher, then, is causes a deadlock, this is predictable, what I want to do is have a log for when this cases happen because this cases usually happen. So by knowing that we are using runBlocking and we are trying to dispatch to this Main Thread I could get the stacktrace and print warning of the deadlock.
how about checking Thread.currentThread() then?
(or Looper on Android)