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

129
Views
Angular stop making api request after given milliseconds even if it's not succeeded

I am trying to fetch status from backend until the condition is met but I don't want to overload server by making request forever :) .I want to stop making request after one minute. here is the code

  this.statusService
.getStatus(this.itemId).pipe(
repeatWhen(obs => obs.pipe(delay(500))),
filter(data => {
  if(data.status === 'done'){
    return true;
  }else{
    return false;
  }
   }),
take(1)
).subscribe(result =>{
  console.log(‘done')
});

I tried timeout() but it doesn't stop making request

  this.statusService
.getStatus(this.itemId).pipe(
 timeout(60000),
repeatWhen(obs => obs.pipe(delay(500))),
filter(data => {
  if(data.status === 'done'){
    return true;
  }else{
    return false;
  }
   }),
take(1)
).subscribe(result =>{
  console.log(‘done')
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

UPDATED:

One simple solution can be:

const apiCall$ = this.statusService.getStatus(this.itemId)
  .pipe(
    delay(1000),
    repeat(),
    filter(data => (data.status === 'done'))
  );

const timeout$ = of(false).pipe(delay(3000));

// The observable to emit first is used
race([apiCall$, timeout$])
  .pipe(take(1))
  .subscribe(result => {
    console.log(result);
  });
about 4 years ago · Juan Pablo Isaza 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!