aboutsummaryrefslogtreecommitdiff
path: root/includes/fetcher/node_modules/axios/lib/cancel/CancelToken.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-04-14 17:43:06 +0200
committerMinteck <contact@minteck.org>2022-04-14 17:43:06 +0200
commit3071764c42c63f47cd76d80b5b90fe280ac9f0ab (patch)
tree2458441ce5218cc88a8be165b364f174a9ba8e3b /includes/fetcher/node_modules/axios/lib/cancel/CancelToken.js
parentf6e5be4e0ef648d3eb1d8a12edcb48dbb8c31037 (diff)
downloadember-3071764c42c63f47cd76d80b5b90fe280ac9f0ab.tar.gz
ember-3071764c42c63f47cd76d80b5b90fe280ac9f0ab.tar.bz2
ember-3071764c42c63f47cd76d80b5b90fe280ac9f0ab.zip
Fetcher
Diffstat (limited to 'includes/fetcher/node_modules/axios/lib/cancel/CancelToken.js')
-rw-r--r--includes/fetcher/node_modules/axios/lib/cancel/CancelToken.js119
1 files changed, 119 insertions, 0 deletions
diff --git a/includes/fetcher/node_modules/axios/lib/cancel/CancelToken.js b/includes/fetcher/node_modules/axios/lib/cancel/CancelToken.js
new file mode 100644
index 0000000..089d6b9
--- /dev/null
+++ b/includes/fetcher/node_modules/axios/lib/cancel/CancelToken.js
@@ -0,0 +1,119 @@
+'use strict';
+
+var Cancel = require('./Cancel');
+
+/**
+ * A `CancelToken` is an object that can be used to request cancellation of an operation.
+ *
+ * @class
+ * @param {Function} executor The executor function.
+ */
+function CancelToken(executor) {
+ if (typeof executor !== 'function') {
+ throw new TypeError('executor must be a function.');
+ }
+
+ var resolvePromise;
+
+ this.promise = new Promise(function promiseExecutor(resolve) {
+ resolvePromise = resolve;
+ });
+
+ var token = this;
+
+ // eslint-disable-next-line func-names
+ this.promise.then(function(cancel) {
+ if (!token._listeners) return;
+
+ var i;
+ var l = token._listeners.length;
+
+ for (i = 0; i < l; i++) {
+ token._listeners[i](cancel);
+ }
+ token._listeners = null;
+ });
+
+ // eslint-disable-next-line func-names
+ this.promise.then = function(onfulfilled) {
+ var _resolve;
+ // eslint-disable-next-line func-names
+ var promise = new Promise(function(resolve) {
+ token.subscribe(resolve);
+ _resolve = resolve;
+ }).then(onfulfilled);
+
+ promise.cancel = function reject() {
+ token.unsubscribe(_resolve);
+ };
+
+ return promise;
+ };
+
+ executor(function cancel(message) {
+ if (token.reason) {
+ // Cancellation has already been requested
+ return;
+ }
+
+ token.reason = new Cancel(message);
+ resolvePromise(token.reason);
+ });
+}
+
+/**
+ * Throws a `Cancel` if cancellation has been requested.
+ */
+CancelToken.prototype.throwIfRequested = function throwIfRequested() {
+ if (this.reason) {
+ throw this.reason;
+ }
+};
+
+/**
+ * Subscribe to the cancel signal
+ */
+
+CancelToken.prototype.subscribe = function subscribe(listener) {
+ if (this.reason) {
+ listener(this.reason);
+ return;
+ }
+
+ if (this._listeners) {
+ this._listeners.push(listener);
+ } else {
+ this._listeners = [listener];
+ }
+};
+
+/**
+ * Unsubscribe from the cancel signal
+ */
+
+CancelToken.prototype.unsubscribe = function unsubscribe(listener) {
+ if (!this._listeners) {
+ return;
+ }
+ var index = this._listeners.indexOf(listener);
+ if (index !== -1) {
+ this._listeners.splice(index, 1);
+ }
+};
+
+/**
+ * Returns an object that contains a new `CancelToken` and a function that, when called,
+ * cancels the `CancelToken`.
+ */
+CancelToken.source = function source() {
+ var cancel;
+ var token = new CancelToken(function executor(c) {
+ cancel = c;
+ });
+ return {
+ token: token,
+ cancel: cancel
+ };
+};
+
+module.exports = CancelToken;