-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
IMHO if a subscriber is configured as ThreadMode.MAIN, then events to it should always be queued for the next main Thread loop. Ie even if the caller is the main thread, the event would be added to the main thread queue instead of being delivered in the current thread of execution.
I say this because if you have caller1 (background thread) and caller2 (main thread) both posting EventA to a subscriber configured with ThreadMode.MAIN, then even though caller1 posts before caller2, caller1's event may get delivered last.
A classic example of this is where caller1 is notification of an event starting and caller2 is of event ending. Because caller2 is main thread, the order of the events gets reversed.
NB you may not always know what thread your callers will be invoked from, especially if the initiator is from another library.
If it is not palatable to enforce delivery to ThreadMode.MAIN subscribers in a separate main Thread loop, then ThreadMode.MAIN subscribers should be able to be configured to allow this to happen. Adding a new ThreadMode would suffice, eg ThreadMode.MAIN_DEFERRED.