@@ -25,6 +25,7 @@ import com.lambda.threading.runConcurrent
2525import com.lambda.threading.runGameScheduled
2626import com.lambda.threading.runSafe
2727import com.lambda.util.Pointer
28+ import com.lambda.util.collections.updatableLazy
2829import com.lambda.util.selfReference
2930import kotlinx.coroutines.CoroutineDispatcher
3031import kotlinx.coroutines.Dispatchers
@@ -62,11 +63,13 @@ import kotlin.reflect.KProperty
6263 * @property function The function to be executed when the event occurs. This function operates within a [SafeContext].
6364 */
6465class SafeListener <T : Event >(
65- override val priority : Int = 0 ,
66+ priorityProvider : () -> Int ,
6667 override val owner : Any ,
6768 override val alwaysListen : Boolean = false ,
6869 val function : SafeContext .(T ) -> Unit
6970) : Listener<T>(), ReadOnlyProperty<Any?, T?> {
71+ override val priority = updatableLazy(priorityProvider)
72+
7073 /* *
7174 * The last processed event signal.
7275 */
@@ -118,7 +121,7 @@ class SafeListener<T : Event>(
118121 * @return The newly created and registered [SafeListener].
119122 */
120123 inline fun <reified T : Event > Any.listen (
121- priority : Int = 0 ,
124+ noinline priority : () -> Int = modulePriorityOr0Getter ,
122125 alwaysListen : Boolean = false,
123126 noinline function : SafeContext .(T ) -> Unit = {}
124127 ): SafeListener <T > {
@@ -163,7 +166,7 @@ class SafeListener<T : Event>(
163166 */
164167 fun <T : Event > Any.listen (
165168 kClass : KClass <out T >,
166- priority : Int = 0 ,
169+ priority : () -> Int = modulePriorityOr0Getter ,
167170 alwaysListen : Boolean = false,
168171 function : SafeContext .(T ) -> Unit = {},
169172 ): SafeListener <T > {
@@ -205,7 +208,7 @@ class SafeListener<T : Event>(
205208 * @return The newly created and registered [SafeListener].
206209 */
207210 inline fun <reified T : Event > Any.listenOnce (
208- priority : Int = 0 ,
211+ noinline priority : () -> Int = modulePriorityOr0Getter ,
209212 alwaysListen : Boolean = false,
210213 noinline predicate : SafeContext .(T ) -> Boolean = { true },
211214 ): ReadWriteProperty <Any ?, T ?> {
@@ -253,7 +256,7 @@ class SafeListener<T : Event>(
253256 * @return The newly created and registered [SafeListener].
254257 */
255258 inline fun <reified T : Event > Any.listenConcurrently (
256- priority : Int = 0 ,
259+ noinline priority : () -> Int = modulePriorityOr0Getter ,
257260 alwaysListen : Boolean = false,
258261 scheduler : CoroutineDispatcher = Dispatchers .Default ,
259262 noinline function : suspend SafeContext .(T ) -> Unit = {},
0 commit comments