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

177
Vistas
I have multiple return statements that require an RJXS Delay. Is there a way to make the operator into a constant?

For instance, I have the below pseudo code:

public action1(): 
    return stuff.pipe(delay(15000)); 

public action2(): 
    return stuff.pipe(delay(15000)); 

public action3(): 
    return stuff.pipe(delay(15000)); 

The delay is identical for each return and will not change. But instead of having it as a static value, I would like to make it into a constant that can be easily referenced and modified if needed. Something like the below pseudo code:

Const delay = pipe(delay(15000)) 

public action1(): 
    return stuff.delay; 

public action2(): 
    return stuff.delay; 

public action3(): 
    return stuff.delay;

I have tried to directly reference the delay by using const but I am getting errors when attempting this. I am using the RJXS Delay operator. The primary question is, Is there a way to convert this operator into a constant that can be used in multiple areas?

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

0

You can define a generic function which will accept observer and and bind delay with it and return.

You can do something like bellow

const getAfterDelay = (observer) => observer.pipe(delay(15000));

public action1(): 
    return getAfterDelay(stuff); 

public action2(): 
    return getAfterDelay(stuff);  

public action3(): 
    return getAfterDelay(stuff); 
about 4 years ago · Juan Pablo Isaza Denunciar

0

Create an Extension Method

declare module 'rxjs/internal/Observable' {
  interface Observable<T> {
    delay(): Observable<T>;
  }
}

Observable.prototype.delay = function(): Observable<any> {
  return this.pipe(delay(15000));
};

This allows for the syntax that you're looking for: stuff.delay();.


Observable Delay Extension Method in Typescript for StackBlitz example.

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