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

80
Vistas
Early return from a subscribe block in a function

I am new to JavaScript. I am trying to do an early return on error from a subscribe block.

This is what I have

public doSomething() {
   this.updateData(data)
     .subscribe((result) => {
                   // do something
                }, 
                (err) => {
                   console.error("Error");
                   return;
                   // require an early return from the block
                   // so rest of the function isn't executed. 
     });
   // do other work
}

Any pointers will be appreciated.

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

0

The best solution would be:

public doSomething() {
   this.updateData(data)
     .subscribe((result) => {
                   // do something
                   // do other work
                }, 
                (err) => {
                   console.error("Error");
                   return;
                   // require an early return from the block
                   // so rest of the function isn't executed. 
     });
}

But you can also use await with async:

public async doSomething() {
       const result = await this.updateData(data);
       if (!result) return;
       // do other things
         
}
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