How to make a periodical request to the server in Angular?

There is a page with some data that is updated every n time upon request from the http service, sometimes updated upon request(reset time n). Now this is done using setInterval and clearInterval. It is suspected that there is a more beautiful and intuitive way.
Plus, you want to make an update of the data through time n only after the completion of the current request.
Thanks for all future advice.

p.s. Angular 7+
March 19th 20 at 08:40
2 answers
March 19th 20 at 08:42
Something like this:
import { interval } from 'rxjs';
import { switchMap } from 'rxjs/operators';

const requests$ = interval(300).pipe(
 switchMap(() => http.get('path'))
)
and how to run it right? and then on the interval - Nick.Runolfss commented on March 19th 20 at 08:45
once I have restarted to complete a previous request
p.s. Queries to the server "heavy" and run for 5-6 seconds - Nick.Runolfss commented on March 19th 20 at 08:48
To increase the interval, put it in the constructor - delpha26 commented on March 19th 20 at 08:51
@delpha26, the goal is to run in n time after the completion of the current request. Increasing the time interval won't do it.
And so it is in the constructor - Nick.Runolfss commented on March 19th 20 at 08:54
@Nick.Runolfss, Read setTimeout vs setInterval plus recursion or async await and you will have happiness - Polly.Fisher commented on March 19th 20 at 08:57

Find more questions by tags TypeScriptAngular