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

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

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 Report

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 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!