Skip to content

Better way to set CoroutineContext#DEBUG value #316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dmytrodanylyk opened this issue Apr 10, 2018 · 0 comments
Closed

Better way to set CoroutineContext#DEBUG value #316

dmytrodanylyk opened this issue Apr 10, 2018 · 0 comments

Comments

@dmytrodanylyk
Copy link
Contributor

Currently CoroutineContext#DEBUG rely on system property kotlinx.coroutines.debug.

private const val DEBUG_PROPERTY_NAME = "kotlinx.coroutines.debug"

private val DEBUG = run {
    val value = try { System.getProperty(DEBUG_PROPERTY_NAME) }
        catch (e: SecurityException) { null }
    when (value) {
        "auto", null -> CoroutineId::class.java.desiredAssertionStatus()
        "on", "" -> true
        "off" -> false
        else -> error("System property '$DEBUG_PROPERTY_NAME' has unrecognized value '$value'")
    }
}

In Android we usually rely on BuildConfig.DEBUG flag which indicate if app was build in debug or production mode.

Currently to set CoroutineContext#DEBUG value we need to use following code:

System.setProperty("kotlinx.coroutines.debug", if (BuildConfig.DEBUG) "on" else "off")

Which is not type safe, so my proposal is to:

  • make CoroutineContext#DEBUG_PROPERTY_NAME public, also move "on", "off", "auto" to public constants as well
  • or make alternative, simpler mechanism to change CoroutineContext#DEBUG value
dmytrodanylyk added a commit to dmytrodanylyk/kotlinx.coroutines that referenced this issue Apr 10, 2018
- make `CoroutineContext#DEBUG_PROPERTY_NAME` public, also move `"on"`, `"off"`, `"auto"` to public constants as well
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants