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

fix(bufferTime): do not create buffer when unsubscribed #1949

Closed
wants to merge 1 commit into from

Conversation

kwonoj
Copy link
Member

@kwonoj kwonoj commented Sep 15, 2016

Description:
This PR fixes checking if given bufferCreationInterval is null or not, to execute legit paths when only timespan's supplied.

Related issue (if exists):

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.144% when pulling 3730663 on kwonoj:fix-buffertime-emptyinterval into 6bd3423 on ReactiveX:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.128% when pulling f67d710 on kwonoj:fix-buffertime-emptyinterval into ea983c3 on ReactiveX:master.

@@ -120,7 +120,7 @@ class BufferTimeSubscriber<T> extends Subscriber<T> {
private scheduler: Scheduler) {
super(destination);
const context = this.openContext();
this.timespanOnly = bufferCreationInterval == null || bufferCreationInterval < 0;
this.timespanOnly = bufferCreationInterval === null || bufferCreationInterval < 0;
Copy link
Member

Choose a reason for hiding this comment

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

Help me understand plz, why is there a notable difference between undefined and null here? i.e. why the fact that == null would match undefined too is a problem?

Copy link
Member Author

Choose a reason for hiding this comment

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

wow, it's my bad. apologize. This isn't legit complete fix and code should be updated more.

Copy link
Member

Choose a reason for hiding this comment

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

Phew! I was racking my brain!! 😅😅

@kwonoj kwonoj added the blocked label Sep 16, 2016
@kwonoj kwonoj force-pushed the fix-buffertime-emptyinterval branch 2 times, most recently from 9a046ae to bc8be00 Compare September 18, 2016 01:42
this.closeContext(context);
const closeAction = context.closeAction;
closeAction.unsubscribe();
this.remove(closeAction);

if (this.timespanOnly) {
if (this.timespanOnly && this.contexts !== null) {
Copy link
Member Author

Choose a reason for hiding this comment

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

this is actual changes, do not attempt to open buffer if it's already unsubscribed.

Copy link
Member

Choose a reason for hiding this comment

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

Can we get a regression test around this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure. This occurs with async context, not able to think trivial way to create test cases at the moment writing PR. Let me think a bit more.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought this bit, but wasn't able to come up with clean way to create test coverage via test scheduler (or synchronous way) to mimic unsubscription occurs before scheduled action triggered.

@kwonoj kwonoj changed the title fix(bufferTime): correct bufferCreationInterval check for null fix(bufferTime): do not create buffer when unsubscribed Sep 18, 2016
@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.128% when pulling 59b149c on kwonoj:fix-buffertime-emptyinterval into e91d113 on ReactiveX:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.128% when pulling 59b149c on kwonoj:fix-buffertime-emptyinterval into e91d113 on ReactiveX:master.

1 similar comment
@coveralls
Copy link

coveralls commented Sep 18, 2016

Coverage Status

Coverage remained the same at 97.128% when pulling 59b149c on kwonoj:fix-buffertime-emptyinterval into e91d113 on ReactiveX:master.

@kwonoj kwonoj removed the blocked label Sep 18, 2016
@kwonoj
Copy link
Member Author

kwonoj commented Oct 4, 2016

I think PR #1998 covers same issue and also having test coverage backing it, closing this PR without merging.

@kwonoj kwonoj closed this Oct 4, 2016
@kwonoj kwonoj deleted the fix-buffertime-emptyinterval branch October 4, 2016 03:34
3n-mb added a commit to 3n-mb/rxjs that referenced this pull request Jan 17, 2018
Observing functions (callbacks) are given to `.subscribe(next, error, complete)` by an outside code. But `rxjs` dictates a context of execution, instead of leaving it `undefined`. It sort of disrespects separation between callbacks that come from outside, and its own internals on the public API of the library.
As a result, there are issues ReactiveX#3229, ReactiveX#1981, ReactiveX#1949, ReactiveX#2140, that happen due to `rxjs` mangling with execution context. Library behaves in an unexpected way.

This change fixes an unsanctioned introduction of context to callback.
Now, it is possible, that this weird behaviour was introduced to help some other parts of the lib. Tests should show this. And may be those places should change instead of keeping users of the library puzzled.
@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error on complete when using .bufferTime().take() and supplying a maxBufferSize
3 participants