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

When a subject is multicasted, first subscription next event in its observer synchronously, the second subscription will get the reverse sequence of event #6976

Open
sanmaopep opened this issue May 23, 2022 · 1 comment

Comments

@sanmaopep
Copy link

sanmaopep commented May 23, 2022

Describe the bug

When a subject is subscribed into two subscription: a & b

In subscription a:
console a value
next a value synchronously and recursively (for instance 1, 2, 3, 4, 5)

In subscription b:
console a value

and subject next a value 1 so 1 will be multicasted to a & b

And subscription a will console 1, 2, 3, 4, 5, which meets the demand
But subscription b will console 5, 4, 3, 2, 1, in this case the normal event sequence is reversed

Expected behavior

subscription a & b console the same event sequence

subscription a will console 1, 2, 3, 4, 5
subscription b will also console 1, 2, 3, 4, 5

Reproduction code

const test$ = new Subject();

// a subscription
test$.subscribe((current) => {
  console.log('a', current);
  if(current < 5) {
    test$.next(current + 1)
  }
})

// b subscription
test$.subscribe((current) => {
  console.log('b', current);
})

test$.next(1);

// a 1
// a 2
// a 3
// a 4
// a 5

// b 5
// b 4
// b 3
// b 2
// b 1


### Reproduction URL

_No response_

### Version

7.2.0

### Environment

_No response_

### Additional context

_No response_
@iskalyakin
Copy link

iskalyakin commented Jun 23, 2023

Looks like current behavior is correct. "next" is called synchronously from "a", and because all its callbacks are called synchronously too, all these calls take place before first callback call in "b".

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

No branches or pull requests

2 participants