summaryrefslogtreecommitdiff
path: root/includes/external/addressbook/node_modules/p-cancelable/index.js
diff options
context:
space:
mode:
authorRaindropsSys <raindrops@equestria.dev>2023-11-17 23:25:29 +0100
committerRaindropsSys <raindrops@equestria.dev>2023-11-17 23:25:29 +0100
commit953ddd82e48dd206cef5ac94456549aed13b3ad5 (patch)
tree8f003106ee2e7f422e5a22d2ee04d0db302e66c0 /includes/external/addressbook/node_modules/p-cancelable/index.js
parent62a9199846b0c07c03218703b33e8385764f42d9 (diff)
downloadpluralconnect-953ddd82e48dd206cef5ac94456549aed13b3ad5.tar.gz
pluralconnect-953ddd82e48dd206cef5ac94456549aed13b3ad5.tar.bz2
pluralconnect-953ddd82e48dd206cef5ac94456549aed13b3ad5.zip
Updated 30 files and deleted 2976 files (automated)
Diffstat (limited to 'includes/external/addressbook/node_modules/p-cancelable/index.js')
-rw-r--r--includes/external/addressbook/node_modules/p-cancelable/index.js110
1 files changed, 0 insertions, 110 deletions
diff --git a/includes/external/addressbook/node_modules/p-cancelable/index.js b/includes/external/addressbook/node_modules/p-cancelable/index.js
deleted file mode 100644
index 93bb224..0000000
--- a/includes/external/addressbook/node_modules/p-cancelable/index.js
+++ /dev/null
@@ -1,110 +0,0 @@
-export class CancelError extends Error {
- constructor(reason) {
- super(reason || 'Promise was canceled');
- this.name = 'CancelError';
- }
-
- get isCanceled() {
- return true;
- }
-}
-
-// TODO: Use private class fields when ESLint 8 is out.
-
-export default class PCancelable {
- static fn(userFunction) {
- return (...arguments_) => {
- return new PCancelable((resolve, reject, onCancel) => {
- arguments_.push(onCancel);
- // eslint-disable-next-line promise/prefer-await-to-then
- userFunction(...arguments_).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 => {
- if (!this._isCanceled || !onCancel.shouldReject) {
- this._isPending = false;
- resolve(value);
- }
- };
-
- const onReject = error => {
- this._isPending = false;
- reject(error);
- };
-
- const onCancel = handler => {
- if (!this._isPending) {
- throw new Error('The `onCancel` handler was attached after the promise settled.');
- }
-
- this._cancelHandlers.push(handler);
- };
-
- Object.defineProperties(onCancel, {
- shouldReject: {
- get: () => this._rejectOnCancel,
- set: boolean => {
- this._rejectOnCancel = boolean;
- }
- }
- });
-
- executor(onResolve, onReject, onCancel);
- });
- }
-
- then(onFulfilled, onRejected) {
- // eslint-disable-next-line promise/prefer-await-to-then
- return this._promise.then(onFulfilled, onRejected);
- }
-
- catch(onRejected) {
- // eslint-disable-next-line promise/prefer-await-to-then
- return this._promise.catch(onRejected);
- }
-
- finally(onFinally) {
- // eslint-disable-next-line promise/prefer-await-to-then
- return this._promise.finally(onFinally);
- }
-
- cancel(reason) {
- if (!this._isPending || this._isCanceled) {
- return;
- }
-
- this._isCanceled = true;
-
- if (this._cancelHandlers.length > 0) {
- try {
- for (const handler of this._cancelHandlers) {
- handler();
- }
- } catch (error) {
- this._reject(error);
- return;
- }
- }
-
- if (this._rejectOnCancel) {
- this._reject(new CancelError(reason));
- }
- }
-
- get isCanceled() {
- return this._isCanceled;
- }
-}
-
-Object.setPrototypeOf(PCancelable.prototype, Promise.prototype);