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
rxjs from array execute one by one in same order

I need to execute observables created from array. The condition is next observable should wait until previous observable has been completed. Thanks in advance :-).

export class AppComponent{
    arr: number[] = [5, 4, 1, 2, 3];    
    fetchWithObs() {
        from(this.arr)
          .pipe(
            map((value) => {
              return this.getData(value);
            })
          )
          .subscribe((data) => {
            console.log(data);
            /**
             * The expoected output should be
             * 5 completed
             * 4 completed
             * 1 completed
             * 2 completed
             * 3 completed
             */
          });
      }
    
      getData(p: number) {
        return new Observable<string>((s) => {
          setTimeout(() => {
            s.next(`${p} completed`);
            s.complete();
          }, p * 1000);
        });
      }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try concatMap.

export class AppComponent{
    arr: number[] = [5, 4, 1, 2, 3];    
    fetchWithObs() {
        from(this.arr)
          .pipe(
            concatMap(this.getData)
          )
          .subscribe(console.log);
      }
    
      getData(p: number) {
        return new Observable<string>((s) => {
          setTimeout(() => {
            s.next(`${p} completed`);
            s.complete();
          }, p * 1000);
        });
      }
}

Stackblitz: https://stackblitz.com/edit/typescript-axx8gf?file=index.ts

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!