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

Dmytro Danylyk

04/09/2018, 10:25 AM
@elizarov can we make
CoroutineContext#DEBUG
field public and mutable? In android we usually rely on generated
BuildConfig.DEBUG
field.
e

elizarov

04/09/2018, 10:26 AM
I’m not sure I follow the use-case
d

Dmytro Danylyk

04/09/2018, 10:27 AM
I want to set
CoroutineContext#DEBUG
field based on if it’s android debug or production build.
In android we have generated
BuildConfig.DEBUG
field which is
false
if it’s debug build and
true
if it;s prodcution.
So example of usage on android would be something like:
CoroutineContext.DEBUG = BuildConfig.DEBUG
For now I can do this via reflection. Let me know if you want me to create ticket and describe use-case. I think I can contribute as well.
e

elizarov

04/09/2018, 11:01 AM
I see. You have different kinds of builds…
d

Dmytro Danylyk

04/09/2018, 12:06 PM
So, is there any reason to not make it possible to change
CoroutineContext#DEBUG
?
v

Vsevolod Tolstopyatov [JB]

04/09/2018, 4:26 PM
The good thing about the immutability of
static final
variable is that JIT can inline it everywhere and eliminate unnecessary branches/checks etc., so debug code has no influence on performance with debug mode off. Why changing
DEBUG
via
kotlinx.coroutines.debug
system property is not applicable?
k

kenkyee

04/09/2018, 5:57 PM
Android's BuildConfig.DEBUG is also static final FWIW
d

Dmytro Danylyk

04/09/2018, 9:32 PM
@Vsevolod Tolstopyatov [JB] because we don't want to have debug flag's all over the places. We usually have single source file (Application class) where we do all initialisation, e.g. we initialise image loader with debug logs, http client with debug logs, etc. And everything is controlled via BuildConfig.DEBUG flag.
v

Vsevolod Tolstopyatov [JB]

04/10/2018, 7:43 AM
@Dmytro Danylyk why calling
System.setProperty("kotlinx.coroutines.debug", "on")
depending on
BuildConfig.DEBUG
in the beginning of Application class is not applicable in such case?
e

elizarov

04/10/2018, 7:45 AM
We can also support “injectable” providers for DEBUG via META-INF/services extension mechanism where you’d provide your own implementation of the class that returns debug status. This way, too, we can keep it
static final
field, yet allow for project-specific configuration.
d

Dmytro Danylyk

04/10/2018, 8:13 AM
@Vsevolod Tolstopyatov [JB] this will work, however: it’s not type safe and you need to write mapping between BuildConfig.DEBUG true/false and coroutine DEBUG on/off/auto.
Would be great at least have private const val
DEBUG_PROPERTY_NAME = "kotlinx.coroutines.debug"
public
@elizarov not sure if it will work for android, I never tried to do this.
let’s continue in https://github.com/Kotlin/kotlinx.coroutines/issues/316, I think as a first step making constants public would be great step forward.
6 Views