Skip to content

Event dispatcher preprocessor #11

Description

@jhrldev

Proposal

Provide a preprocessing step in event dispatch, allowing it to flexibly change channels of the event before sending it through dispatch logic, or cancelling them.

Example

Event:

interface AccountMoneyChangeEvent : Event {
    val amount: Int
}

Preprocessor:

class AccountMoneyChangeEventPreprocessor : EventDispatchPreprocessor<AccountMoneyChangeEvent> {
    fun onPreprocess(event: AccountMoneyChangeEvent, dispatch: DispatchConfiguration) {
        if (event.amount < 0) {
            dispatch.channels += ChannelSet.Include("withdraw")
        } else if (event.amount > 0) {
            dispatch.channels += ChannelSet.Include("deposit")
        } else {
            dispatch.cancel()
        }
    }
}

eventManager.registerPreprocessor<AccountMoneyChangeEvent>(AccountMoneyChangeEventPreprocessor())

Also, if Characteristics get implemented, the preprocessor could also change characteristics of events, but this will occur after Factory Characteristic Handling, so the preprocessor will have priority.

Downsides

A Dispatch Preprocessor could make it harder to figure why a event is not being dispatched as expected.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions