Skip to content

Event dispatcher preprocessor #11

@jhrldev

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions