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

268
Views
¿Cómo ejecuto el código después de la suscripción de la función devuelta?

Tengo el siguiente código que se parece a esto:

 foo(){ return this.service.asyncFunction(); } //in another function: this.foo().subscribe(() => { some_code });

¿Es posible refactorizar la función foo para que se vea así?

 foo(){ return this.service.asyncFunction().subscribe(); }

¿Pero aún podrá ejecutar some_code después de la suscripción?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si desea suscribirse dentro de foo() y aún poder enviar el observable, puede hacer esto

 foo(){ const myObs = this.service.asyncFunction(); myObs.subscribe(); return myObs; }

En algún otro lugar del código, puedes hacer esto

 this.foo().subscribe(() => { some_code });

Pero si quieres usar foo() y darle algo de código, entonces puedes hacer esto

 foo(callback){ this.service.asyncFunction().subscribe(callback); }

Y en otro lugar del código, haz esto

 for(() => { some code });
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!