Do Coroutines have something like `_Thread_._isMai...
# coroutines
s
Do Coroutines have something like
_Thread_._isMainThread_
which allows me to check that the current code is actually running in a Dispatchers.IO context for example?
1
s
Something like this should work
coroutineContext[ContinuationInterceptor] == Dispatchers.Main
s
Thank you
a
What are you looking to do by checking this?
s
I'm hunting down a problem and wanted to have a multiplatform way to ensure that my suspend method is actually called in a coroutine running on "main". I know that I can ensure that withContext(), but I want to assert at certain points that everything is set up correctly.
l
If you want to be able to check that regardless of whether you're in a suspending function, here's a small multiplatform library I made just for that, where calling
isMainThread
will get you covered: https://github.com/LouisCAD/Splitties/tree/main/modules/mainthread
🙏 1