Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!