For #15279 - review: set LazyMonitored to private.
This commit is contained in:
parent
c96e16112f
commit
afa080c956
|
@ -20,14 +20,14 @@ object ComponentInitCount {
|
||||||
* A convenience function for setting the [LazyMonitored] property delegate, which wraps
|
* A convenience function for setting the [LazyMonitored] property delegate, which wraps
|
||||||
* [lazy] to add performance monitoring.
|
* [lazy] to add performance monitoring.
|
||||||
*/
|
*/
|
||||||
fun <T> lazyMonitored(initializer: () -> T) = LazyMonitored(initializer)
|
fun <T> lazyMonitored(initializer: () -> T): Lazy<T> = LazyMonitored(initializer)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper around the [lazy] property delegate to monitor for performance related issues.
|
* A wrapper around the [lazy] property delegate to monitor for performance related issues.
|
||||||
* For example, we can count the number of components initialized to see how the number of
|
* For example, we can count the number of components initialized to see how the number of
|
||||||
* components initialized on start up impacts start up time.
|
* components initialized on start up impacts start up time.
|
||||||
*/
|
*/
|
||||||
class LazyMonitored<T>(initializer: () -> T) : Lazy<T> {
|
private class LazyMonitored<T>(initializer: () -> T) : Lazy<T> {
|
||||||
// Lazy is thread safe.
|
// Lazy is thread safe.
|
||||||
private val lazyValue = lazy {
|
private val lazyValue = lazy {
|
||||||
// We're unlikely to have 4 billion components so we don't handle overflow.
|
// We're unlikely to have 4 billion components so we don't handle overflow.
|
||||||
|
|
|
@ -17,12 +17,6 @@ class LazyMonitoredTest {
|
||||||
ComponentInitCount.count.set(0)
|
ComponentInitCount.count.set(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `WHEN using the convenience function THEN it returns a lazy monitored`() {
|
|
||||||
val actual = lazyMonitored { }
|
|
||||||
assertEquals(LazyMonitored::class, actual::class)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `WHEN accessing a lazy monitored THEN it returns the initializer value`() {
|
fun `WHEN accessing a lazy monitored THEN it returns the initializer value`() {
|
||||||
val actual by lazyMonitored { 4 }
|
val actual by lazyMonitored { 4 }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user