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 }