Client applications sends request to server, that could potentially take long to complete. Once request is finished or failed, client should wait some period of time (i.e. 10 seconds) and then again send the request.
Current working solution is this:
appRequest = new Subject();
ngOnInit(): void {
this.appRequest.delay(10000).subscribe(() => this.refresh());
this.refresh();
}
refresh() {
this.api.getApplications().subscribe(a => {
this.updateApplications(a);
this.appRequest.next();
},() => this.appRequest.next()
);
}
Is there a more elegant solution for this?
EDIT:
I could use timer with regular intervals but I don't want to send new request unless previous request has finished. Only after previous request has finished, I want to wait 10 seconds and do send request again. This should repeat indefinitely.
getApplications()
function is generated by swagger and it internally uses angular's http client library. Current observation is that unless you subscribe to Observable
returned by getApplications()
, it will not send request to server.
getApplications()
function is generated by swagger and it uses angular's http client library. Unless I subscribe to observable provided bygetApplications()
it does not even send request to server. – Cagey