Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!