In the suspending function or block, is priortisin...
# coroutines
a
In the suspending function or block, is priortising
currentCoroutineContext()
over
coroutineContext
always good? Shouldn't we then deprecate the
coroutineContext
suspending variable or make it internal? I am asking as having multiple similar methods unnecessarily increase the cognitive overload
e
notice the different packages: kotlin.coroutines.coroutineContext kotlinx.coroutines.currentCoroutineContext the second can only be used from kotlinx.coroutines (and should always be, to avoid confusion with CoroutineScope.coroutineContext) but there are non-kotlinx coroutines which use the first
a
So is it good to say one should always prefer one(
currentCoroutineContext()
) over the other? Especially when using Coroutines in an application Also are you trying to say that since both of these exists in different libs we can't deprecate one in favour of the other?
e
cannot remove
coroutineContext
because it is necessary for things using the
kotlin.coroutines
infrastructure (such as
SequenceBuilder
) but it's confusing in
kotlinx.coroutines
(note the
x
), which is probably what you're working with more often