listen

inline fun <E : Event> EventListenerRegistrar.listen(propertiesConsumer: ConfigurerFunction<EventListenerRegistrationProperties>? = null, crossinline typeMismatchResult: EventListenerContext.() -> EventResult = { invalid() }, crossinline listenerFunction: suspend EventListenerContext.(E) -> EventResult): EventListenerRegistrationHandle(source)

为特定事件类型注册事件处理器函数。

Parameters

E

The type of event to register the listener for.

propertiesConsumer

An optional function that consumes the configuration properties of the listener registration. The function should have the signature ConfigurerFunction<EventListenerRegistrationProperties>.

typeMismatchResult

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.

listenerFunction

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.