EventBus icon indicating copy to clipboard operation
EventBus copied to clipboard

`CancellableEventBus#addListener` might be confusing with the boolean parameter

Open Jonathing opened this issue 8 months ago • 1 comments

The cancellable event bus has custom addListener events to handle listeners that cancel the event. There is one such method: addListener(boolean, Consumer<T>), where true causes the listener to always be cancelled. Even with documentation, I fear that this method may be confusing to those reading the code, and is an unnecessary additional parameter for what is effectively a different method call.

I think this should be replaced with something like addListernerCancelling(Consumer<T>).

Jonathing avatar Apr 24 '25 01:04 Jonathing

Technically it's an addAlwaysCancellingListener(Consumer<T>) but I thought that was a bit verbose and would make people question why the never cancelling one isn't called addNeverCancellingListener(Consumer<T>).

The reason why never cancelling listeners have the same addListener(Consumer<T>) name and signature on both CancellableEventBus and EventBus is for cross-compatibility. For example, if you don't care about cancelling the event, your add listener code shouldn't break just because the event no longer implements the Cancellable characteristic.

PaintNinja avatar Apr 24 '25 10:04 PaintNinja