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

327
Views
¿Cómo llamar secuencialmente a la función asíncrona dentro del método Observable?

Tengo el siguiente método:

 public classMethod( payload: Payload, ): Observable<Result> { const { targetProp } = payload; let target; return this.secondClass.secondClassMethod({ targetProp }).pipe( delayWhen(() => // some other actions ), ); }

Es fundamental establecer este valor target antes de llamar a this.secondClass.secondClassMethod .

¿Es posible llamar a un método asincrónico regular como este?

 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(() => ), ); }

En otras palabras, me gustaría invocar el método classMethod para que classMethod establezca la variable target dentro de él y luego será posible usar target en la construcción de retorno.

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

He intentado cubrir el método asíncrono en:

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

PERO me dijeron que esta portada invocará en paralelo con

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

paralelo no es una opción aquí :(

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Puede convertir la promesa en un observable usando from y 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!