mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-23 22:30:47 +08:00
Add WeakRef
This commit is contained in:
parent
eb9a64e5a0
commit
3731bd9822
@ -11,6 +11,13 @@ inline class UnsafeWeakRef<T>(private val weakRef: WeakRef<T>) {
|
||||
fun get(): T = weakRef.get() ?: error("WeakRef is released")
|
||||
fun clear() = weakRef.clear()
|
||||
|
||||
/**
|
||||
* Provides delegate value.
|
||||
*
|
||||
* ```kotlin
|
||||
* val bot: Bot by param.unsafeWeakRef()
|
||||
* ```
|
||||
*/
|
||||
operator fun getValue(thisRef: Any?, property: KProperty<*>): T? = this.get()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user