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

Only trigger the timeoutScheduler when not yet subscribed. #313

Merged
merged 1 commit into from
Jan 16, 2015

Conversation

daschl
Copy link
Contributor

@daschl daschl commented Jan 15, 2015

This changeset makes sure that the (costly) delayed execution task
is schedule when noone is subscribed yet - since the whole purpose
of its existence is to dispose if not subscribed yet.

Note that a future improvement might be also to unsubscribe if one
subscribes before the cleanup actually runs.

note that for some reason I couldn't get a valid unit test together (I didn't try very hard though). If you have any pointers on how to do it without changing too much let me know.

@@ -273,7 +273,7 @@ public void onNext(T t) {
ReferenceCountUtil.retain(t); // Retain so that post-buffer, the ByteBuf does not get released. Release will be done after reading from the subject.
state.bufferedSubject.onNext(t);

if (state.casTimeoutScheduled()) {// Schedule timeout once.
if (state.casTimeoutScheduled() && state.state == 0) {// Schedule timeout once and when not subscribed yet.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's safer to do state.state == STATES.UNSUBSCRIBED.ordinal()

This smells like a race (as state can be changed concurrently) but the state does not change from SUBSCRIBED/DISPOSED to UNSUBSCRIBE so we are safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup makes sense.. Do you have a hint on unit testing?

This changeset makes sure that the (costly) delayed execution task
is schedule when noone is subscribed yet - since the whole purpose
of its existence is to dispose if not subscribed yet.

Note that a future improvement might be also to unsubscribe if one
subscribes before the cleanup actually runs.
@daschl
Copy link
Contributor Author

daschl commented Jan 16, 2015

@NiteshKant good now? :)

NiteshKant added a commit that referenced this pull request Jan 16, 2015
Only trigger the timeoutScheduler when not yet subscribed.
@NiteshKant NiteshKant merged commit b544e02 into ReactiveX:0.x Jan 16, 2015
@NiteshKant
Copy link
Member

Yep, thanks @daschl !

@NiteshKant NiteshKant added this to the 0.4.5 milestone Jan 16, 2015
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.

None yet

2 participants