aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt
index 39dac5247..5f0ccd404 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeLimitedSet.kt
@@ -2,9 +2,12 @@ package at.hannibal2.skyhanni.utils
import kotlin.time.Duration
-class TimeLimitedSet<T>(expireAfterWrite: Duration) {
+class TimeLimitedSet<T>(
+ expireAfterWrite: Duration,
+ private val removalListener: (T) -> Unit = {},
+) {
- private val cache = TimeLimitedCache<T, Unit>(expireAfterWrite)
+ private val cache = TimeLimitedCache<T, Unit>(expireAfterWrite) { key, _ -> key?.let { removalListener(it) } }
fun add(element: T) = cache.put(element, Unit)