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

321
Views
How to call async function inside Observable method sequentially?

I have the following method:

  public classMethod(
    payload: Payload,
  ): Observable<Result> {
    const { targetProp } = payload;
    let target;

    return this.secondClass.secondClassMethod({ targetProp }).pipe(
      delayWhen(() =>
        // some other actions
      ),
    );
  }

It is critical to set this target value before calling this.secondClass.secondClassMethod.

Is it possible to call regular async method like this:

  public classMethod(
    req: classMethodRequest,
  ): Observable<classMethodResponse> {
    const { targetProp } = req;
    let target;

    /**
    **  Calling async method here to set ```target```
    ** like 
    ** target = await someAsyncMethod(targetProp)
    **/

    return this.secondClass.secondClassMethod({ targetProp }).pipe(
      delayWhen(() =>
      ),
      
    );
  }

In other words, I would like to invoke method classMethod so, that classMethod will set target variable within it and then it will be possible to use target in the returning construction

return this.secondClass.secondClassMethod({ targetProp }).pipe(
      delayWhen(() =>
      ),
    );

I've tried to cover async method in:

 from(
      (async () => {
        target = await this.someAsyncMethod.setTarget(targetProp);
      })(),
    );

BUT I was told that this cover will invoke in parallel with

return this.secondClass.secondClassMethod({ targetProp }).pipe(
      delayWhen(() =>
      ),
    );

parallel is not an option here :(

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You can convert the promise to an observable using from and use switchMap

return from(this.someAsyncMethod.setTarget(targetProp)).pipe(
  switchMap(target => this.secondClass.secondClassMethod({ targetProp }),
  delayWhen(() => ... ),
);
about 4 years ago · Santiago Gelvez 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!