Is there a way to get Coroutine object that curren...
# coroutines
t
Is there a way to get Coroutine object that current running ? I'm confusd why AbstractCoroutine is also Job and CoroutineScope.
d
It is
CoroutineScope
so that it can be used as receiver of coroutine builder function lambdas. The API does not expose this relationship, and it is thus an implementation detail.
Presumably to save on object allocations.
t
oh, it's why runBlocking provides BlockingCoroutine as receiver CoroutineScope object.
f
Out of curiosity, why do you want to get the "Coroutine object that current running"? IMO, the "ambient" information provided to a coroutine should be accessed via
coroutineContext
.
t
I wanted to look at it with a debugger to get better understanding.
d
As Pedro said, try
coroutineContext[Job]
to get the job associated with the current context.
t
I think
Coroutine object
means pair of Continuation and AbstructCoroutine. CoroutineContext is not Coroutine.