listen
inline fun <E : Event> EventListenerRegistrar.listen(propertiesConsumer: ConfigurerFunction<EventListenerRegistrationProperties>? = null, crossinline defaultResult: EventListenerContext.() -> EventResult = { EventResult.invalid }, crossinline listenerFunction: suspend EventListenerContext.(E) -> EventResult)
为特定事件类型注册事件处理器函数。
Parameters
E
The type of event to register the listener for.
properties Consumer
An optional function that consumes the configuration properties of the listener registration. The function should have the signature ConfigurerFunction<EventListenerRegistrationProperties>.
default Result
The default result function that will be invoked if the event is not of type E. The function should have the signature EventContext.() -> EventResult. By default, it returns an invalid result.
listener Function
The listener function that will be invoked when the event is fired. The function should have the signature suspend EventContext.(E) -> EventResult, where EventContext represents the context of the event and E is the event type.
Throws
If the listener function is not provided.