From 87f99addbba13f83b7d40b9f9069e2e3aece8e93 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Wed, 13 Dec 2023 12:59:01 +0200 Subject: [PATCH] Update SuspendLazy --- .../org/koitharu/kotatsu/parsers/util/SoftSuspendLazy.kt | 4 ++++ .../kotlin/org/koitharu/kotatsu/parsers/util/SuspendLazy.kt | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/util/SoftSuspendLazy.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/util/SoftSuspendLazy.kt index 0a460a0b..91dcd4cc 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/util/SoftSuspendLazy.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/util/SoftSuspendLazy.kt @@ -30,4 +30,8 @@ class SoftSuspendLazy( } suspend fun tryGet() = runCatchingCancellable { get() } + + fun peek(): T? { + return cachedValue?.get() + } } diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/util/SuspendLazy.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/util/SuspendLazy.kt index cb9a911a..6a37a1c3 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/util/SuspendLazy.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/util/SuspendLazy.kt @@ -32,5 +32,10 @@ class SuspendLazy( suspend fun tryGet() = runCatchingCancellable { get() } + @Suppress("UNCHECKED_CAST") + fun peek(): T? { + return cachedValue?.takeUnless { it === Uninitialized } as T? + } + private object Uninitialized }