Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

267
Vistas
How do I run code after returned function subscription?

I have the following code that looks like this:

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

//in another function:

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

Is it possible to refactor the foo function too look like this:

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

But still be able to run some_code after the subscription?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you want to subscribe inside foo() and still be able to send the observable you can do this

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

Somewhere else in the code, you can do this

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

But if you want to use foo() and give it some code then you can do this

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

And somewhere else in the code, do this

for(() => { some code });
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda