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

166
Vistas
What is a forkJoin alternative that allows parallel requests to complete if one of them fails

I want to run some requests in parallel using forkJoin and combine their results as shown below. However, when one of the requests fails, the rest of the subscriptions are automatically cancelled by the browser. What is a simple alternative to forkJoin that lets me run requests in parallel and if one subscription fails, the rest are allowed to complete?

const posts = this.http.get("https://myApi.com/posts?userId=1");
const albums = this.http.get("https://myApi.com/albums?userId=1");

forkJoin([posts, albums]).subscribe((result) => {
  this.print(result[0], result[1]);
});

print(res1, res2) {
  const message = res1.text + res2.text;
  console.log(message);
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can achieve that using forkJoin, however, you have to handle the errors for each sub Observable separately using catchError to prevent canceling the stream if any error occurred.

You can try something like the following:

// import { catchError } from 'rxjs/operators';
// import { forkJoin, of } from 'rxjs';

const posts = this.http
  .get('https://myApi.com/posts?userId=1')
  .pipe(catchError((err) => of(err)));
const albums = this.http
  .get('https://myApi.com/albums?userId=1')
  .pipe(catchError((err) => of(err)));

forkJoin([posts, albums]).subscribe((result) => {
  this.print(result[0], result[1]);
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

I would make a function like

forkJoinReplaceErrors<T,R>(
  observables: Observable<T>[],
  ifError: ObservableInput<R>
) {
  return forkJoin(
    observables.pipe(
      catchError(() => ifError)
    )
  );
}

and then use that instead of forkJoin. Then it's more reusable and can be unit tested.

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