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

ReplaySubject subscription handler is called before it is subscribed #2044

Closed
ventsislav-georgiev opened this issue Oct 17, 2016 · 1 comment · Fixed by #2046
Closed

ReplaySubject subscription handler is called before it is subscribed #2044

ventsislav-georgiev opened this issue Oct 17, 2016 · 1 comment · Fixed by #2046
Assignees
Labels
bug Confirmed bug

Comments

@ventsislav-georgiev
Copy link

RxJS version:
[email protected]

Code to reproduce:

let subject = new Rx.ReplaySubject();
subject.next(1);
subject.subscribe(function (data) {
  console.log(data);
  if (data < 3) { data++; subject.next(data); }
});

Expected behavior:
Output: 1, 2, 3

Actual behavior:
Output: 1

Additional information:
This works properly in RxJS v4

It seems that the issue comes from this code: https://github.com/ReactiveX/rxjs/blob/master/src/ReplaySubject.ts#L40
Where we first call the subsrcibe handler with the previous values, before we actually subscribe him for next values.

@benlesh benlesh added the bug Confirmed bug label Oct 17, 2016
@benlesh benlesh self-assigned this Oct 17, 2016
jayphelps pushed a commit that referenced this issue Oct 24, 2016
…tion function (#2046)

Removed reliance on inherited `_subscribe` method from `Subject`. ReplaySubject has different behaviors during subscription for notifying new subscribers after a completion or error. After moving the `super._subscribe` call before the notification from saved `_events`, it was apparent that the inherited behavior from `Subject` was stopping the subscriber before it could be notified properly.

fixes #2044
@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
bug Confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants