-
Notifications
You must be signed in to change notification settings - Fork 3k
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(IteratorObservable): get new iterator for each subscription #2497
Conversation
This definitely a bug fix. The issue is that it's going to be a breaking change for somebody. So we might want to put this in the next major (which we should publish soon). But it's debatable. The problem, better outlined is this: const data = new Int32Array([1, 2, 3, 4, 5]);
const source$ = Observable.from(data);
source$.toArray().subscribe(x => console.log(x)); // [1, 2, 3, 4, 5]
source$.toArray().subscribe(x => console.log(x)); // [] That's not what users would expect at all. It should behave like the standard Array implementation. However, we might have one crazy person relying on this behavior. The work around to get that behavior again would be to pass the actual const data = new Int32Array([1, 2, 3, 4, 5]);
const iterator = data[Symbol.iterator]();
// "new" appropriate behavior
const source1$ = Observable.from(data);
source1$.toArray().subscribe(x => console.log(x)); // [1, 2, 3, 4, 5]
source1$.toArray().subscribe(x => console.log(x)); // [1, 2, 3, 4, 5]
// "old" behavior, if desired
const source2$ = Observable.from(iterator);
source2$.toArray().subscribe(x => console.log(x)); // [1, 2, 3, 4, 5]
source2$.toArray().subscribe(x => console.log(x)); // [] |
Pros of major: no one will be surprised, no code will break in production. Cons: it will be a different number. Pros of patch: it will look like a harmless corner-casey number bump, like this is a corner case. Cons of patch: there is a positive probability someone will be surprised, and that someone could be a user of an app in production. I vote for major.
http://semver.org/#spec-item-8 It depends what we consider our public API. Usually its tests + docs. We don't have any test that asserts the buggy behavior as normal. In our docs we say
It could be understood that the Iterator creation side effect happens once, independent of multiple subscriptions, like the promise constructor side effect does as well. |
I think this is a major bump for the reasons outline by Andre. |
Removing labels for patch to avoid accidental check in. |
@kwonoj can you resolve conflicts against |
sure. |
b427cad
to
1ea94c2
Compare
@benlesh rebased to |
Generated by 🚫 dangerJS |
907cd25
to
b6f942b
Compare
Now this can go into master as breaking change. |
BREAKING CHANGE: IteratorObservable no longer share iterator between subscription - closes ReactiveX#2496
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. |
Description:
Our
IteratorObservable
gets an iterator from the object once only when it's constructed, so any subsequent subscription is not able to iterate since the first subscription will make iterator completes.This PR updates behavior to get corresponding new iterator per each subscription, allows any subscription can correctly iterate object. I'm labeling this for next patch version, since I believe this isn't breaking changes.
Related issue (if exists):