Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda