Fix for missing pre-binding events #156
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR resolves an issue related to the order of the bind operations that, in some cases, causes missing events due to the producer producing the events before the binding happens.
The idea is to accumulate the events until all the connections are bound and the subscriptions happen.
On the one hand, the
MviCore
library does not know about theObservable
until we call the bind method. A new component calledAccumulatorSubject
helps to accumulate the events produced by anObservable
until told to stop doing so anddrains
all the accumulated events. In this case, until all theConnections
are bound. On the other hand, a UnicastSubject inside theBinding
also collects the events once theConsumer
subscribes toObservable
.The reason behind adding
UnicastSubject
in the middle is that there might exist bounded but not subscribed connections. So if all the bindings are bound, we can drain them but keep the not-consumed events inUnicastSubjects
.Because the
UnicastSubject
accepts only a singleObserver
, and theBinder
class is reusable for the sameLifecycle
object (we can call thestart
andstop
operations multiple times), it creates a new instance for each binding every time we invoke thestart
method of theLifecycle
.Also, due to the usage of multiple instances of
Binder
for subscribing to differentLifecycle
events, we keep track of all theBinder
instances. We may use the sameObservables
as the source in distinctBinder
instances. So, once we bind all the connections from all theBinders
, we can drain theAccumulatorSubjects
.This is not the final solution, just an ideation around a possible one