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

245
Vistas
RxJS timeout on NGXS Select Observable?

I am facing a strange issue and hoping someone can shed some light for me.

I have a slice of my state that is getting updated on an interval (let's say every 10 seconds for the sake of this question). I want to subscribe to the selector for that piece of state and timeout if the state is not updated for that value in X amount of time. I am using rxjs timeout operator to do this.

@Select(MyState.myValue) myValue$: Observable<number>;

setInterval(() => //updating MyState with a new myValue, 10000);

myValue$
    .pipe(timeout(20000))
    .subscribe({
        next: myValue => console.log(myValue),
        error: err => console.log(err)
    })

What I am seeing is that the TimeoutError is being thrown after 20 seconds regardless of how frequently the values are being emitted.

HOWEVER, the timeout DOES work if I just apply it to the Observable returned by the interval() function. With the below code, I never see the TimeoutError, which is what I expect to happen with the code above for NGXS.

interval(10000)
    .pipe(timeout(20000))
    .subscribe({
        next: myValue => console.log(intervalValue),
        error: err => console.log(err)
    })

So it seems like there's some issue with the Observable being returned by the Select decorator?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

when using timeout operator, you should provide a callback function to the with property. otherwise it emit an TimeoutError;

for you problem, you should provide a value to each parameter as well. each parameter defines The time allowed between each pushed value from the source before the resulting observable will timeout

example =>

test$.pipe(
   timeout({
     each: 1000,
     with: () => functionExecutedWithTimeout()
   })
)

refer official documentation of timeout operator for more information

over 4 years ago · Santiago Trujillo Denunciar

0

or you can use debounceTime it is rxjs operator and it is easier

example

this.subject.pipe(
debounceTime(500))
    .subscribe({
        next: myValue => //do anything,
        error: err => //do anything
    })

resource debounceTime

over 4 years ago · Santiago Trujillo 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