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
}
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'))
);
}