Skip to content

Commit d586cc9

Browse files
committed
Allow customization of default scheduler name on JVM
Fixes #3231
1 parent 61ba10d commit d586cc9

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

kotlinx-coroutines-core/common/src/internal/SystemProps.common.kt

+11
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ internal fun systemProp(
5656
return parsed
5757
}
5858

59+
/**
60+
* Gets the system property indicated by the specified [property name][propertyName],
61+
* or returns [defaultValue] if there is no property with that key.
62+
*
63+
* **Note: this function should be used in JVM tests only, other platforms use the default value.**
64+
*/
65+
internal fun systemProp(
66+
propertyName: String,
67+
defaultValue: String
68+
): String = systemProp(propertyName) ?: defaultValue
69+
5970
/**
6071
* Gets the system property indicated by the specified [property name][propertyName],
6172
* or returns `null` if there is no property with that key.

kotlinx-coroutines-core/jvm/src/scheduling/Tasks.kt

+13-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,19 @@ import kotlinx.coroutines.internal.*
99
import java.util.concurrent.*
1010

1111

12-
// Internal debuggability name + thread name prefixes
13-
internal const val DEFAULT_SCHEDULER_NAME = "DefaultDispatcher"
12+
/**
13+
* Name of the default scheduler.
14+
*
15+
* Customization provided for when there's no control over used dispatchers/schedulers (i.e when
16+
* [Dispatchers.Default] is used within third-party libraries), or when overall default configuration
17+
* is acceptable and only the default scheduler name needs to be changed.
18+
*
19+
* Useful for filtering log messages.
20+
*/
21+
@JvmField
22+
internal val DEFAULT_SCHEDULER_NAME = systemProp(
23+
"kotlinx.coroutines.scheduler.default.name", "DefaultDispatcher"
24+
)
1425

1526
// 100us as default
1627
@JvmField

0 commit comments

Comments
 (0)