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:
Diffstat (limited to 'app/assets/javascripts/lib/utils/poll.js')
-rw-r--r--app/assets/javascripts/lib/utils/poll.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/app/assets/javascripts/lib/utils/poll.js b/app/assets/javascripts/lib/utils/poll.js
index a900ff34bf5..7f0c65868c2 100644
--- a/app/assets/javascripts/lib/utils/poll.js
+++ b/app/assets/javascripts/lib/utils/poll.js
@@ -46,6 +46,19 @@ import { normalizeHeaders } from './common_utils';
* 4. If HTTP response is 200, we poll.
* 5. If HTTP response is different from 200, we stop polling.
*
+ * @example
+ * // With initial delay (for, for example, reducing unnecessary requests)
+ *
+ * const poll = new Poll({
+ * resource: this.service,
+ * method: 'fetchNotes',
+ * successCallback: () => {},
+ * errorCallback: () => {},
+ * });
+ *
+ * // Performs the first request in 2.5s and then uses the `Poll-Interval` header.
+ * poll.makeDelayedRequest(2500);
+ *
*/
export default class Poll {
constructor(options = {}) {
@@ -74,6 +87,10 @@ export default class Poll {
this.options.successCallback(response);
}
+ makeDelayedRequest(delay = 0) {
+ this.timeoutID = setTimeout(() => this.makeRequest(), delay);
+ }
+
makeRequest() {
const { resource, method, data, errorCallback, notificationCallback } = this.options;