Fix crash on plugin reload (#895)

* Update Event.kt

* Update Event.kt
This commit is contained in:
CranberrySoup 2024-01-18 21:57:54 +00:00 committed by GitHub
parent 5dfc08aabb
commit 5af1b80cb7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,18 +3,24 @@ package com.lagradost.cloudstream3.utils
class Event<T> {
private val observers = mutableSetOf<(T) -> Unit>()
val size : Int get() = observers.size
val size: Int get() = observers.size
operator fun plusAssign(observer: (T) -> Unit) {
observers.add(observer)
synchronized(observers) {
observers.add(observer)
}
}
operator fun minusAssign(observer: (T) -> Unit) {
observers.remove(observer)
synchronized(observers) {
observers.remove(observer)
}
}
operator fun invoke(value: T) {
for (observer in observers)
observer(value)
synchronized(observers) {
for (observer in observers)
observer(value)
}
}
}
}