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

tap-complete not called for last observable inside zip #7467

Open
janhommels opened this issue Apr 23, 2024 · 1 comment
Open

tap-complete not called for last observable inside zip #7467

janhommels opened this issue Apr 23, 2024 · 1 comment
Labels
bug Confirmed bug

Comments

@janhommels
Copy link

janhommels commented Apr 23, 2024

Describe the bug

Zip tears down all inner observables when it completes before they can run their tap implementations.
When adding a complete-function to all inner observables of a tap, the observable which will complete last and cause the whole zip to complete will not run their complete function iside their tap operator.

I understand that there are multiple solutions to this issue like using the finalize operator, however people don't expect the complete callback to not be called and it took me a while to figure that out.
I'm not sure if this issues comes up in other inner/outer-observable scenarios.

Expected behavior

The complete-callback inside the tap operator should always be called, regardless of when/how it completes.
In the example below, "2 completed" will not be logged. Expected behaviour would be that it will be logged.

Reproduction code

zip(
  of(1).pipe(tap({ next: n => console.log(`${n} nexted`), complete: _ => console.log("1 completed") })),
  of(2).pipe(tap({ next: n => console.log(`${n} nexted`), complete: _ => console.log("2 completed") }))
).subscribe({next: n => console.log(n), complete: _ => console.log("the end")})

Reproduction URL

https://playcode.io/1845913

Version

8.0.0-alpha.3

Environment

No response

Additional context

No response

@jakovljevic-mladen jakovljevic-mladen added the bug Confirmed bug label Apr 23, 2024
@demensky
Copy link
Contributor

demensky commented Apr 23, 2024

It simply unsubscribes until complete happens. This can be clearly seen if more elements are passed to the second observable:

https://playcode.io/1846169

zip(
  of(1, 2).pipe(
    tap({
      next: n => console.log('1 nexted:', n),
      unsubscribe: () => console.log('1 unsubscribe'),
      complete: () => console.log('1 completed'),
    })
  ),
  of('a', 'b', 'c').pipe(
    tap({
      next: n => console.log('2 nexted:', n),
      unsubscribe: () => console.log('2 unsubscribe'),
      complete: () => console.log('2 completed'),
    })
  )
).subscribe({
  next: n => console.log('result', n),
  complete: () => console.log('the end'),
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

3 participants