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

PublishSubject doesn't work with concatWith operator #750

Closed
haashem opened this issue Mar 29, 2024 · 2 comments
Closed

PublishSubject doesn't work with concatWith operator #750

haashem opened this issue Mar 29, 2024 · 2 comments

Comments

@haashem
Copy link

haashem commented Mar 29, 2024

In the below example, concatWith should emits the values added by stream 2:

void exampleOf(String of, {required void Function() action}) {
  print('\n———Example $of———');
  action();
}

exampleOf('concatWith(Iterable<Stream>)', action: () {
    final stream1 = Stream.fromIterable([2, 3, 4]);
    final stream2 = PublishSubject<int>();

    stream1.concatWith([stream2]).listen(
      (event) => print('append: $event'),
      onDone: () => print('Done'),
    );
    stream2.add(5);
    stream2.close();
  });

Expected:

———Example concatWith(Iterable<Stream>)———
append: 2
append: 3
append: 4
append: 5
Done

Actual:

———Example concatWith(Iterable<Stream>)———
append: 2
append: 3
append: 4
Done

But if I replace PublishSubject with BehaviorSubject it works as expected.
I think it's a bug.

@haashem haashem changed the title PublishSubject doesn't works with concatWith operator PublishSubject doesn't work with concatWith operator Mar 29, 2024
@hoc081098
Copy link
Collaborator

hoc081098 commented Mar 29, 2024

all elements from stream1 will be delivered to the result stream with microtask delays (async by default).

At this time, adding value to PublishSubject is ignored, because the stream1 is listening.

stream1: --2--3--4--|
stream2: 5
result     : --2--3--4--|

Sent from my 2201117TG using FastHub

@hoc081098
Copy link
Collaborator

hoc081098 commented Mar 30, 2024

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