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

126
Views
forJoin for dynamic amount of requests not printing when done

So I'm using forkJoin to complete a dynamic amount of requests. It's working great, but I'm not getting my console log when subscribing to the forkJoin? All the examples I've seen just do a basic subscribe like I am, so I'm not really understanding why it isn't working.

I've added the DataService calls also for more clarity. Perhaps I'm doing something wrong there and that's why the forkJoin isn't working?

Here is my code:

let requests = [];
newAdds.forEach(ele => {
    requests.push(this._dataService.add(ID1, ID2));
});

forkJoin(requests).subscribe(ret => {
    console.log(ret);
  }
);

 add(id1, id2) {
    class Add{
      ID1: number;
      ID2: string;
    };
    let data = new Add();
    data.ID1 = id1;
    data.ID2 = id2;


    let cmd = "Add";
    return this.put(this.urlAdmin() + cmd, data);
  }


protected put(cmd: string, body: any) {
 let headers = new HttpHeaders();
 headers.append('Content-Type', 'application/json');

 return this._http.put(cmd, body, {
   headers: headers
 });
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

forkJoin will only emit if and only if all observables have completed.

This one example will never emit (interval never ends)

forkJoin([interval(1000), interval(2000)]).subscribe(console.log); // won't emit

This example will emit [0, 0] value after 2000ms.

forkJoin([timer(1000), timer(2000)]).subscribe(console.log); // emit [0,0]

If one observable does't emit a single value but completes, forkJoin won't emit

forkJoin(of()).subscribe(console.log) // won't emit

If at least 1 observable throws an error, forkJoin will never complete.

forkJoin([of(1), throwError(1)]).subscribe(console.log); // will never emit

ForkJoin doc

about 4 years ago · Juan Pablo Isaza Report
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!