Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
rxJS mergeMap does not complete when nested

Here is a pseudo function that is supposed to complete but it doesnt ObservableFunctionA iterates over an array of data, as it spits out the items ObservableFunctionB runs through each item

ObservableFunctionA(parameter1,parameter2)
            .pipe(
                mergeMap((res) => {
                //use res
                // -->parameter3,parameter4
                    return ObservableFunctionB(parameter3,parameter4)
                })
              )
              .subscribe({
                next(x) {},
                error(err) {
                  console.error("something wrong occurred: " + err);
                },
                complete() {
                  console.log("done");
                },
              });

This is ObservableFunctionB

const ObservableFunctionB = (p1,p2) => {
 
  return new Observable((observer) => {
    promiseA
      .then((res) => {

        //Do stuff

        observer.next(manipulatedRes);

        if (condition) {
          console.log("This is actually logged, the line below doesnt get executed!");
          observer.complete();
        }
      })
      .catch((err) => {
        observer.error(err);
      });
  });
};

The condition is reached, the line is logged yet the observer complete function is not called

Why?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!