Significant restructuring of subscriptions#603
Significant restructuring of subscriptions#603akarnokd wants to merge 2 commits intoReactiveX:masterfrom
Conversation
|
RxJava-pull-requests #539 SUCCESS |
…entity is problematic.
|
RxJava-pull-requests #540 SUCCESS |
|
@headinthebox does this match what you were hoping for regarding Subscriptions? |
There was a problem hiding this comment.
Is a SerialSubscription really a MultipleAssignmentSubscription in the inheritance manner? I don't think they are as their functionality is different and thus it doesn't seem to pass the "is a" test.
There was a problem hiding this comment.
The SerialSubscription differs from MultipleAssignmentSubscription by a single operation: once the reference is swapped, the old is unsubscribed in SerialSubscription but not in the other.
There was a problem hiding this comment.
I'd like to entertain the idea of inheritance a bit, since maybe it will put more structure in the mess of subscriptions.
Subscription
// adds isUnsubscribed
BooleanSubscription extends Subscription
// adds setSubscription(...) throws if sets twice (like "val")
SingleAssignmentSubscription extends BooleanSubscription
// allows to setSubscription twice, leaves previous unchanged (like "var")
MultipleAssignmentSubscription extends SingleAssignmentSubscription
// allows to setSubscription twice, unsubscribes old one.
SerialSubscription extends MultipleAssignmentSubscription previous
// adds add/remove(...)
CompositeSubscription extends BooleanSubscription implements List
It is always safe to pass a DerivedSubscription where you expect a BaseSubscription (unless you want swapping a subscription to throw, but I would say that is more a promise from the caller that they will never set the subscription more than once).
On the other hand, perhaps this is over-design.
…to every Registry (ReactiveX#606)
I've re-abstracted the subscriptions to be more uniform and maintenance friendly.
onUnsubscribe(Issue BooleanSubscription should be properly wired up to allow inheritance #591).BooleanSubscription.withActionto allow wrapping a single-time unsubscription action.AbstractAtomicSubscriptionwhich manages the lock-free manipulations through callbacks.MultipleAssignmentSubscriptionto have two extension points in its logic, which allows simpler subclass implementations ofSerialSubscriptionandSingleAssignmentSubscription.MultipleAssignmentSubscriptiondoes not extendAbstractAtomicSubscriptionbecause it has a much simpler state-transition logic whereas theAbstractAtomicSubscriptionwith its callbacks would be an overkill.CompositeSubscriptionandRefCountSubscriptionto useAbstractAtomicSubscription.SafeObservableSubscriptionto useSingleAssignmentSubscriptioninstead of duplicating its behavior.Subscriptionswith anunsubscribeAllmethod to capture the exception collection behavior when unsubscribing from multiple subscriptions.empty0(),empty1()andempty2()convenience methods to Actions. Haven't checked if such no-op ActionX instances are created manually somewhere.ValuedCompositeSubscription<T>class where a value can be associated with aSubscriptionkey.