https://kotlinlang.org logo
#coroutines
Title
# coroutines
t

tateisu

11/08/2018, 6:31 PM
Is there a way to get Coroutine object that current running ? I'm confusd why AbstractCoroutine is also Job and CoroutineScope.
d

Dico

11/08/2018, 6:34 PM
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

tateisu

11/08/2018, 6:43 PM
oh, it's why runBlocking provides BlockingCoroutine as receiver CoroutineScope object.
f

Felix

11/08/2018, 6:58 PM
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

tateisu

11/08/2018, 7:12 PM
I wanted to look at it with a debugger to get better understanding.
d

Dico

11/08/2018, 8:30 PM
As Pedro said, try
coroutineContext[Job]
to get the job associated with the current context.
t

tateisu

11/09/2018, 1:24 AM
I think
Coroutine object
means pair of Continuation and AbstructCoroutine. CoroutineContext is not Coroutine.