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

@ -6,15 +6,21 @@ class Event<T> {
val size: Int get() = observers.size val size: Int get() = observers.size
operator fun plusAssign(observer: (T) -> Unit) { operator fun plusAssign(observer: (T) -> Unit) {
synchronized(observers) {
observers.add(observer) observers.add(observer)
} }
}
operator fun minusAssign(observer: (T) -> Unit) { operator fun minusAssign(observer: (T) -> Unit) {
synchronized(observers) {
observers.remove(observer) observers.remove(observer)
} }
}
operator fun invoke(value: T) { operator fun invoke(value: T) {
synchronized(observers) {
for (observer in observers) for (observer in observers)
observer(value) observer(value)
} }
} }
}