ReactiveX / ReactiveX/rxjs

tap-complete not called for last observable inside zip

Open
#7,467 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
31.7k
Forks
3k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reproduction URL or the provided zip/tap example and confirm that the second complete callback is missing. Read the zip and tap operator implementations to trace teardown and completion ordering. Done means the last observable's tap complete callback runs and the existing reproduction behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.