Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ThreadMode.MAIN_ASYNC to queue event delivery for a future loop of the Main UI Thread. #308

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

william-ferguson-au
Copy link
Contributor

Added ThreadMode.MAIN_ASYNC to allow a subscriber to declare that it wants to be called in the Main UI thread but the event should be queued for delivery by a future Main UI loop.

Ie MAIN_ASYNC subscribers never received delivery directly from the poster's thread, even if it is the Main UI thread.

This ensures that events sent to MAIN_ASYNC subscribers are delivered in the order in which they are posted, regardless of the poster's thread. Extremely useful for ensuring that events that denote steps in a process (eg beginning, end) and are used to present UI state are delivered in the order in which they are created.

This is a solution for #307 that allows existing behaviour to continue.

…wants to be called in the Main UI thread but the events should be queued for delivery in the order in which they are posted.

 Ie MAIN_ASYNC subscribers never received delivery directly from the poster's thread, even if it is the Main UI thread.
@william-ferguson-au
Copy link
Contributor Author

william-ferguson-au commented Jul 1, 2016

The intent of an EventBus is to decouple event emitter from event consumer. By posting an event on the same thread as the emitter you are coupling the emitter to the consumer based on execution context. It is overriding the execution context explicitly defined by the subscriber.

The contract that the emitter has with the EventBus is that the EventBus will accept delivery of an event. The emitter expects this to be a quick operation and is not expecting their thread of execution to be highjacked by some unknown subscriber that happens to want the notification in the same type of thread.

The contract that a subscriber has with the EventBus is that it receives the events in the order in which they were posted to the EventBus.

IMHO there should only be 2 delivery modes MAIN_ASYNC and ASYNC. This would greatly simplify the EventBus. It would also simplify the semantics of emitters and subscribers.

@greenrobot
Copy link
Owner

We'll look into this.
Tests for this behavior are missing, @greenrobot-team can look into that.

@patton73
Copy link

patton73 commented Sep 18, 2017

Thanks a lot for your effort.
I would say that If order of events is not guaranteed then the bus has a real problem. Hope this will be fixed as well.
Thanks.

@greenrobot-team
Copy link
Collaborator

greenrobot-team commented Sep 19, 2017

This is now also part of the plain-java-new branch, including a test. This is expected to be in the 3.1.0 release, we welcome your feedback. -ut

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants