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

114
Vistas
How can I wait for code/ subscription to finish before the function returns

I need to wait for the 2 subscription in my function to finish before it returns the value of 'this.getRows('employee')' . What would be the best way to do that? Maybe rxjs would help but I am bad with that. Thank you in advance

getEmployeesTable(): Table {
    this.backendService.getEmployeeSummaryTable().subscribe((employees) => {
      this.emloyeeSummary = employees;
    });
    this.backendService.getEmployeesTable().subscribe((employees) => {
      this.emloyees = employees;
    });
    setTimeout(() => (table = this.getRows('employee')), 1000); // this does not help

    return this.getRows('employee'); // this should only return after the 2 functions above 
                                     //finished 
  }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

forkJoin will wait for two async operation to be completed

getEmployeesTable():Observable<Table>{
  
  return forkJoin({
    emloyeeSummary: this.backendService.getEmployeeSummaryTable(),
    employees: this.backendService.getEmployeesTable()
  }).pipe(
    tap((res) => {
     this.emloyeeSummary = res.emloyeeSummary;
     this.emloyees = res.employees;
    }),
    map(() => this.getRows('employee'))
  );
}
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