Update SuspendLazy

This commit is contained in:
2023-12-13 12:59:01 +02:00
parent 5758e9f68f
commit 87f99addbb
2 changed files with 9 additions and 0 deletions

View File

@@ -30,4 +30,8 @@ class SoftSuspendLazy<T : Any>(
}
suspend fun tryGet() = runCatchingCancellable { get() }
fun peek(): T? {
return cachedValue?.get()
}
}

View File

@@ -32,5 +32,10 @@ class SuspendLazy<T>(
suspend fun tryGet() = runCatchingCancellable { get() }
@Suppress("UNCHECKED_CAST")
fun peek(): T? {
return cachedValue?.takeUnless { it === Uninitialized } as T?
}
private object Uninitialized
}