aboutsummaryrefslogtreecommitdiff
path: root/node_modules/p-cancelable/index.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-06-04 08:51:19 +0200
committerMinteck <contact@minteck.org>2022-06-04 08:51:19 +0200
commitb22f6770c8bd084d66950655203c61dd701b3d90 (patch)
tree873d7fb19584ec2709b95cc1ca05a1fc7cfd0fc4 /node_modules/p-cancelable/index.js
parent383285ecd5292bf9a825e05904955b937de84cc9 (diff)
downloadequestriadb-b22f6770c8bd084d66950655203c61dd701b3d90.tar.gz
equestriadb-b22f6770c8bd084d66950655203c61dd701b3d90.tar.bz2
equestriadb-b22f6770c8bd084d66950655203c61dd701b3d90.zip
Remove node_modules
Diffstat (limited to 'node_modules/p-cancelable/index.js')
-rw-r--r--node_modules/p-cancelable/index.js103
1 files changed, 0 insertions, 103 deletions
diff --git a/node_modules/p-cancelable/index.js b/node_modules/p-cancelable/index.js
deleted file mode 100644
index 26bd42e..0000000
--- a/node_modules/p-cancelable/index.js
+++ /dev/null
@@ -1,103 +0,0 @@
-'use strict';
-
-class CancelError extends Error {
- constructor(reason) {
- super(reason || 'Promise was canceled');
- this.name = 'CancelError';
- }
-
- get isCanceled() {
- return true;
- }
-}
-
-class PCancelable {
- static fn(userFn) {
- return (...args) => {
- return new PCancelable((resolve, reject, onCancel) => {
- args.push(onCancel);
- userFn(...args).then(resolve, reject);
- });
- };
- }
-
- constructor(executor) {
- this._cancelHandlers = [];
- this._isPending = true;
- this._isCanceled = false;
- this._rejectOnCancel = true;
-
- this._promise = new Promise((resolve, reject) => {
- this._reject = reject;
-
- const onResolve = value => {
- this._isPending = false;
- resolve(value);
- };
-
- const onReject = error => {
- this._isPending = false;
- reject(error);
- };
-
- const onCancel = handler => {
- this._cancelHandlers.push(handler);
- };
-
- Object.defineProperties(onCancel, {
- shouldReject: {
- get: () => this._rejectOnCancel,
- set: bool => {
- this._rejectOnCancel = bool;
- }
- }
- });
-
- return executor(onResolve, onReject, onCancel);
- });
- }
-
- then(onFulfilled, onRejected) {
- return this._promise.then(onFulfilled, onRejected);
- }
-
- catch(onRejected) {
- return this._promise.catch(onRejected);
- }
-
- finally(onFinally) {
- return this._promise.finally(onFinally);
- }
-
- cancel(reason) {
- if (!this._isPending || this._isCanceled) {
- return;
- }
-
- if (this._cancelHandlers.length > 0) {
- try {
- for (const handler of this._cancelHandlers) {
- handler();
- }
- } catch (error) {
- this._reject(error);
- }
- }
-
- this._isCanceled = true;
- if (this._rejectOnCancel) {
- this._reject(new CancelError(reason));
- }
- }
-
- get isCanceled() {
- return this._isCanceled;
- }
-}
-
-Object.setPrototypeOf(PCancelable.prototype, Promise.prototype);
-
-module.exports = PCancelable;
-module.exports.default = PCancelable;
-
-module.exports.CancelError = CancelError;