Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-10 21:07:43 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-10 21:07:43 +0300
commit6f0f893bd87535b61e0ecb1ce069eaa7fcb9e5be (patch)
tree8af92b29c838e9af2fd70f9a4a2314a08f4af922 /app/assets/javascripts/lib
parent8b1228b0d409d7751f01d9fb72ebfbbf62399486 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/lib')
-rw-r--r--app/assets/javascripts/lib/utils/poll_until_complete.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/app/assets/javascripts/lib/utils/poll_until_complete.js b/app/assets/javascripts/lib/utils/poll_until_complete.js
new file mode 100644
index 00000000000..199d0e6f0f7
--- /dev/null
+++ b/app/assets/javascripts/lib/utils/poll_until_complete.js
@@ -0,0 +1,42 @@
+import axios from '~/lib/utils/axios_utils';
+import Poll from './poll';
+import httpStatusCodes from './http_status';
+
+/**
+ * Polls an endpoint until it returns either a 200 OK or a error status.
+ * The Poll-Interval header in the responses are used to determine how
+ * frequently to poll.
+ *
+ * Once a 200 OK is received, the promise resolves with that response. If an
+ * error status is received, the promise rejects with the error.
+ *
+ * @param {string} url - The URL to poll.
+ * @param {Object} [config] - The config to provide to axios.get().
+ * @returns {Promise}
+ */
+export default (url, config = {}) =>
+ new Promise((resolve, reject) => {
+ const eTagPoll = new Poll({
+ resource: {
+ axiosGet(data) {
+ return axios.get(data.url, {
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ ...data.config,
+ });
+ },
+ },
+ data: { url, config },
+ method: 'axiosGet',
+ successCallback: response => {
+ if (response.status === httpStatusCodes.OK) {
+ resolve(response);
+ eTagPoll.stop();
+ }
+ },
+ errorCallback: reject,
+ });
+
+ eTagPoll.makeRequest();
+ });