Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda