I am trying to write a polling method that periodically checks the server to see if a zip file has already been created or not.
I want to do the following:
- Calls (ajax) the API that creates the zip file on the server
- Calls (ajax) another API that checks if a zip file has already been created (polling method)
- Next process
Here is my code snippet β
var success: boolean = false;
this.apiRequest.downloadRequest(params,ApiUrl.URL_FOR_DOWNLOAD_REQUEST)
.then((resObj) => {
var apiRes: IDownloadService = resObj.data;
if (apiRes.status[0].statusCode == "000") {
success = true;
} else {
}
}).then(() => {
if (success) {
<- Polling methodβ ->
this.polling(params).then((zipUrl) => {
console.log(zipUrl);
});
}
});
Can someone give examples of survey methods that will work in this case?
Added:
private polling(params: any): ng.IPromise<any> {
var poller = () => this.apiRequest.polling(params, ApiUrl.URL_FOR_POLLING);
var continuation = () => poller().then((resObj) => {
var apiRes: IDownloadService = resObj.data;
if (apiRes.zipFilePath == "") {
return this.$timeout(continuation, 1000);
} else {
return apiRes.zipFilePath;
}
})
var result: ng.IPromise<any> = continuation();
return result;
}
source
share