Is there some documentation on how to inspect a `C...
# getting-started
d
Is there some documentation on how to inspect a
CoroutineScope
/
CoroutineContext
? I would I unit test this function?
Copy code
fun createCoroutineScope(): CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
So in my test I have to check if the returned
CoroutineScope
is using a
SupervisedJob
or a particular
Dispatcher
how do I do that?? (or any other property of the context/scope)
d
A
CoroutineContext
is basically a type-safe map, the keys are
CoroutineContext.Key
. In your example
scope.coroutineContext[Job]
would give you the
SupervisorJob
(because
Job
has a
companion object
which is the
CoroutineContext.Key
);
scope.coroutineContext[CoroutineDispatcher]
will give you
Dispatchers.Default
in the same way.
d
thanks @diesieben07 where do I find a list of keys? I tried to make Intellij tell me but failed
d
"Show type hierarchy" (
Ctrl-H
) on
CoroutineContext.Key
does it for me. I can't find that in the menus though, I always just use the shortcut 😄
d
oh, for some reason I didn't though of using CoroutineContext.Key hierarchy.... btw you can find it if you do
Ctrl+Shift+A
and look for type hierarchy
hum by the way I can get the job with
scope.coroutineContext[Job]
but than I do not know how to check it's a SupervisorJob. it's not a class, it's a top level function and the implementation is private