question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Canceling Events only work partly

See original GitHub issue

If you call EventBus.cancelEventDelivery() the ‘event’ won’t be canceled completely. Only subscribers, who have subscribed to exactly that event class (and not a parent one of that) won’t get notified. If you have e.g. an onEvent(Object ev) listener and canceling sending of MyCustomEvent in an onEvent(MyCustomEvent) the onEvent(Object) method will still receive it. This is (imho) pretty unexpected behavior.

The error lies here: https://github.com/greenrobot/EventBus/blob/master/EventBus/src/de/greenrobot/event/EventBus.java#L482

Your break only break out the inner loop (subscribers for this class) and not the outer loop (all parent classes of the current event). You should also break out of the outer for loop.

Didn’t know if you wish a labeled loop or putting the abort to the for condition, that’s why I didn’t send a pull request (and because it’s anyway such a small change).

Unfortunately I didn’t find a workaround till this is fixed, to really cancel an event. It seems like you have to keep an own list of canceled events if you use event hierarchy.

I hope the fix can be published soon 😃 Thanks guys for the great lib.

Issue Analytics

  • State:open
  • Created 10 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
william-ferguson-aucommented, Sep 14, 2016

It sounds like you are either a) attempting to have an Event represent two or more discrete events b) have created a Swiss army knife consumers that is trying to respond to an event multiple times in distinct ways.

The first is solved by separating your Event into the underlying Events it actually represents and post them each in turn.

The second is solved by combining the functionality in the multiple subscriber methods in your consumer is a single subscriber for the concrete Event class.

I wouldn’t be (and we don’t) use Event inheritance at all. Instead all subscriptions are for a concrete Event class. It makes it very easy to determine who the producers and who the consumers are when you want to start aggressively refactoring.

You also gain certainty about execution order, because you are never wondering which subscriber is called before another as there is only one subscriber (in a consumer) for an Event.

There’s more, but those are the highlights.

1reaction
Panthaaaacommented, Sep 14, 2016

I don’t think to solution to a buggy feature is to just stop using it. IMHO it’s really helpful to use event inheritance in larger applications (i.e. complex event hierachies) to manage the complexity.

I will add a pull requests with a fix, so this could be integrated into one of the next versions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Gracefully Cancel an Event - Eventbrite Blog
If your event runs for multiple days and only one day is canceled, it's fine to offer a partial or prorated refund to...
Read more >
Damage Limitation When You Need to Cancel Your Event
If the event is being canceled, they should be eligible for a full refund. If only one day or element of a multi-day...
Read more >
How Businesses Are Dealing With Canceled Events
As events around the country are canceled, small businesses are collaborating with clients and customers to find alternatives.
Read more >
Cancel all future meetings in a series - Microsoft Support
The best way to cancel remaining meetings in a series is to send a meeting update with a new end date. Note: Once...
Read more >
What Happens When Your Event is Cancelled Due to ... - Nolo
If the event is fully canceled, offer the option to provide a sponsor credit for a future event. In some cases, you may...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found