Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda