Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nextgis/cancelable-promise

Package Overview
Dependencies
Maintainers
3
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nextgis/cancelable-promise - npm Package Compare versions

Comparing version 1.0.0-alpha.9 to 1.0.0-alpha.10

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

# [1.0.0-alpha.10](https://github.com/nextgis/nextgis_frontend/compare/v1.0.0-alpha.9...v1.0.0-alpha.10) (2020-10-20)
**Note:** Version bump only for package @nextgis/cancelable-promise
# [1.0.0-alpha.9](https://github.com/nextgis/nextgis_frontend/compare/v1.0.0-alpha.8...v1.0.0-alpha.9) (2020-10-15)

@@ -8,0 +16,0 @@

8

lib/cancelable-promise.cjs.js

@@ -1,2 +0,2 @@

/** Bundle of @nextgis/cancelable-promise; version: 1.0.0-alpha.9; author: NextGIS */
/** Bundle of @nextgis/cancelable-promise; version: 1.0.0-alpha.10; author: NextGIS */
'use strict';

@@ -58,3 +58,3 @@

}
GetOrCreateDecorator(name = '') {
WaitForMe(name = '') {
const get = this.get.bind(this);

@@ -76,2 +76,6 @@ const add = this.add.bind(this);

}
/** @deprecated use {@link PromiseControl.WaitForMe } instead */
GetOrCreateDecorator(name = '') {
return this.WaitForMe(name);
}
_onStop() {

@@ -78,0 +82,0 @@ if (this.options.onStop && !this.isLoaded) {

@@ -1,1 +0,1 @@

"use strict";class t extends Error{constructor(){super(),this.name="CancelError",Object.setPrototypeOf(this,t.prototype)}}class e{constructor(t={}){this.options=t,this._promises=new Map}get isLoaded(){return this._promises.size>0}remove(t){this._promises.has(t)&&(this._promises.delete(t),this._onStop())}get(t){return this._promises.get(t)}add(t,e){const s=e||t,i=this._promises.get(s);return this.options.onStart&&!this.isLoaded&&this.options.onStart(),i||(this._promises.set(s,t),t.finally(()=>{this.remove(s)}),t)}abort(){this.isLoaded&&(this._promises.forEach(t=>{t.cancel&&t.cancel()}),this._promises.clear(),this._onStop())}GetOrCreateDecorator(t=""){const e=this.get.bind(this),s=this.add.bind(this);return function(i,r,n){const o=n.value;return t=t||r,n.value=function(...i){const r=e(t);if(r)return r;return s(o.apply(this,i),t)},n}}_onStop(){this.options.onStop&&!this.isLoaded&&this.options.onStop()}}const s=(t,e,s,i)=>{try{t(s(i))}catch(t){e(t)}};let i=0;class r{constructor(e){this.id=i++,this._isCanceled=!1,this._isPending=!0,this._cancelHandlers=[],this._children=[],this._cancelPromise=new Promise((e,s)=>{this._setCanceledCallback=s=>e(s||new t)}),this._promise=Promise.race([this._cancelPromise,new Promise((t,s)=>e(e=>{e instanceof r?this.attach(e):this._isPending=!1,t(e)},t=>{this._isPending=!1,s(t)},t=>{if(!this._isPending)throw new Error("The `onCancel` handler was attached after the promise settled.");this._cancelHandlers.push(t)}))])}static createControl(t){return new e(t)}static resolve(t){return new r(e=>e(t))}static reject(t){return new r((e,s)=>s(t))}static all(t){return new r((e,s)=>{Promise.all(t).then(e).catch(s)})}attach(t){this._isCanceled?t.cancel():this._children.push(t)}then(t,e){const i=new r((i,r)=>{if(this._promise){const n=t=>{e?s(i,r,e,t):r(t)};this._promise.then(e=>{this._isCanceled?n(e):t?s(i,r,t,e):i(e)},n)}});return i._parentPromise=this,this._children.push(i),i}catch(e){return this._isCanceled&&e&&e(new t),this.then(void 0,e)}finally(e){return this._promise?this._promise.finally(e):Promise.reject(this._isCanceled?new t:e)}cancel(){if(this._isCanceled)return this;this._isCanceled=!0;const t=this._getTopParent();if(t&&t.cancel(),this._children&&this._children.forEach(t=>t.cancel()),this._isPending){if(this._cancelHandlers.length)try{for(const t of this._cancelHandlers)t()}catch(t){}this._setCanceledCallback&&this._setCanceledCallback()}return this._destroy(),this}_getTopParent(){let t=this._parentPromise,e=!!t;for(;e;)t&&t._parentPromise?(t=t._parentPromise,e=!!t):e=!1;return t}_destroy(){this._setCanceledCallback=void 0,this._cancelPromise=void 0,this._promise=void 0}}r.CancelError=t,Object.setPrototypeOf(r.prototype,Promise.prototype),module.exports=r;
"use strict";class t extends Error{constructor(){super(),this.name="CancelError",Object.setPrototypeOf(this,t.prototype)}}class e{constructor(t={}){this.options=t,this._promises=new Map}get isLoaded(){return this._promises.size>0}remove(t){this._promises.has(t)&&(this._promises.delete(t),this._onStop())}get(t){return this._promises.get(t)}add(t,e){const s=e||t,i=this._promises.get(s);return this.options.onStart&&!this.isLoaded&&this.options.onStart(),i||(this._promises.set(s,t),t.finally(()=>{this.remove(s)}),t)}abort(){this.isLoaded&&(this._promises.forEach(t=>{t.cancel&&t.cancel()}),this._promises.clear(),this._onStop())}WaitForMe(t=""){const e=this.get.bind(this),s=this.add.bind(this);return function(i,r,n){const o=n.value;return t=t||r,n.value=function(...i){const r=e(t);if(r)return r;return s(o.apply(this,i),t)},n}}GetOrCreateDecorator(t=""){return this.WaitForMe(t)}_onStop(){this.options.onStop&&!this.isLoaded&&this.options.onStop()}}const s=(t,e,s,i)=>{try{t(s(i))}catch(t){e(t)}};let i=0;class r{constructor(e){this.id=i++,this._isCanceled=!1,this._isPending=!0,this._cancelHandlers=[],this._children=[],this._cancelPromise=new Promise((e,s)=>{this._setCanceledCallback=s=>e(s||new t)}),this._promise=Promise.race([this._cancelPromise,new Promise((t,s)=>e(e=>{e instanceof r?this.attach(e):this._isPending=!1,t(e)},t=>{this._isPending=!1,s(t)},t=>{if(!this._isPending)throw new Error("The `onCancel` handler was attached after the promise settled.");this._cancelHandlers.push(t)}))])}static createControl(t){return new e(t)}static resolve(t){return new r(e=>e(t))}static reject(t){return new r((e,s)=>s(t))}static all(t){return new r((e,s)=>{Promise.all(t).then(e).catch(s)})}attach(t){this._isCanceled?t.cancel():this._children.push(t)}then(t,e){const i=new r((i,r)=>{if(this._promise){const n=t=>{e?s(i,r,e,t):r(t)};this._promise.then(e=>{this._isCanceled?n(e):t?s(i,r,t,e):i(e)},n)}});return i._parentPromise=this,this._children.push(i),i}catch(e){return this._isCanceled&&e&&e(new t),this.then(void 0,e)}finally(e){return this._promise?this._promise.finally(e):Promise.reject(this._isCanceled?new t:e)}cancel(){if(this._isCanceled)return this;this._isCanceled=!0;const t=this._getTopParent();if(t&&t.cancel(),this._children&&this._children.forEach(t=>t.cancel()),this._isPending){if(this._cancelHandlers.length)try{for(const t of this._cancelHandlers)t()}catch(t){}this._setCanceledCallback&&this._setCanceledCallback()}return this._destroy(),this}_getTopParent(){let t=this._parentPromise,e=!!t;for(;e;)t&&t._parentPromise?(t=t._parentPromise,e=!!t):e=!1;return t}_destroy(){this._setCanceledCallback=void 0,this._cancelPromise=void 0,this._promise=void 0}}r.CancelError=t,Object.setPrototypeOf(r.prototype,Promise.prototype),module.exports=r;

@@ -1,2 +0,2 @@

/** Bundle of @nextgis/cancelable-promise; version: 1.0.0-alpha.9; author: NextGIS */
/** Bundle of @nextgis/cancelable-promise; version: 1.0.0-alpha.10; author: NextGIS */
/**

@@ -56,3 +56,3 @@ * Thrown when consumer tries to connect when he already connected.

}
GetOrCreateDecorator(name = '') {
WaitForMe(name = '') {
const get = this.get.bind(this);

@@ -74,2 +74,6 @@ const add = this.add.bind(this);

}
/** @deprecated use {@link PromiseControl.WaitForMe } instead */
GetOrCreateDecorator(name = '') {
return this.WaitForMe(name);
}
_onStop() {

@@ -76,0 +80,0 @@ if (this.options.onStop && !this.isLoaded) {

@@ -1,1 +0,1 @@

class t extends Error{constructor(){super(),this.name="CancelError",Object.setPrototypeOf(this,t.prototype)}}class e{constructor(t={}){this.options=t,this._promises=new Map}get isLoaded(){return this._promises.size>0}remove(t){this._promises.has(t)&&(this._promises.delete(t),this._onStop())}get(t){return this._promises.get(t)}add(t,e){const s=e||t,i=this._promises.get(s);return this.options.onStart&&!this.isLoaded&&this.options.onStart(),i||(this._promises.set(s,t),t.finally(()=>{this.remove(s)}),t)}abort(){this.isLoaded&&(this._promises.forEach(t=>{t.cancel&&t.cancel()}),this._promises.clear(),this._onStop())}GetOrCreateDecorator(t=""){const e=this.get.bind(this),s=this.add.bind(this);return function(i,r,n){const o=n.value;return t=t||r,n.value=function(...i){const r=e(t);if(r)return r;return s(o.apply(this,i),t)},n}}_onStop(){this.options.onStop&&!this.isLoaded&&this.options.onStop()}}const s=(t,e,s,i)=>{try{t(s(i))}catch(t){e(t)}};let i=0;class r{constructor(e){this.id=i++,this._isCanceled=!1,this._isPending=!0,this._cancelHandlers=[],this._children=[],this._cancelPromise=new Promise((e,s)=>{this._setCanceledCallback=s=>e(s||new t)}),this._promise=Promise.race([this._cancelPromise,new Promise((t,s)=>e(e=>{e instanceof r?this.attach(e):this._isPending=!1,t(e)},t=>{this._isPending=!1,s(t)},t=>{if(!this._isPending)throw new Error("The `onCancel` handler was attached after the promise settled.");this._cancelHandlers.push(t)}))])}static createControl(t){return new e(t)}static resolve(t){return new r(e=>e(t))}static reject(t){return new r((e,s)=>s(t))}static all(t){return new r((e,s)=>{Promise.all(t).then(e).catch(s)})}attach(t){this._isCanceled?t.cancel():this._children.push(t)}then(t,e){const i=new r((i,r)=>{if(this._promise){const n=t=>{e?s(i,r,e,t):r(t)};this._promise.then(e=>{this._isCanceled?n(e):t?s(i,r,t,e):i(e)},n)}});return i._parentPromise=this,this._children.push(i),i}catch(e){return this._isCanceled&&e&&e(new t),this.then(void 0,e)}finally(e){return this._promise?this._promise.finally(e):Promise.reject(this._isCanceled?new t:e)}cancel(){if(this._isCanceled)return this;this._isCanceled=!0;const t=this._getTopParent();if(t&&t.cancel(),this._children&&this._children.forEach(t=>t.cancel()),this._isPending){if(this._cancelHandlers.length)try{for(const t of this._cancelHandlers)t()}catch(t){}this._setCanceledCallback&&this._setCanceledCallback()}return this._destroy(),this}_getTopParent(){let t=this._parentPromise,e=!!t;for(;e;)t&&t._parentPromise?(t=t._parentPromise,e=!!t):e=!1;return t}_destroy(){this._setCanceledCallback=void 0,this._cancelPromise=void 0,this._promise=void 0}}r.CancelError=t,Object.setPrototypeOf(r.prototype,Promise.prototype);export default r;
class t extends Error{constructor(){super(),this.name="CancelError",Object.setPrototypeOf(this,t.prototype)}}class e{constructor(t={}){this.options=t,this._promises=new Map}get isLoaded(){return this._promises.size>0}remove(t){this._promises.has(t)&&(this._promises.delete(t),this._onStop())}get(t){return this._promises.get(t)}add(t,e){const s=e||t,i=this._promises.get(s);return this.options.onStart&&!this.isLoaded&&this.options.onStart(),i||(this._promises.set(s,t),t.finally(()=>{this.remove(s)}),t)}abort(){this.isLoaded&&(this._promises.forEach(t=>{t.cancel&&t.cancel()}),this._promises.clear(),this._onStop())}WaitForMe(t=""){const e=this.get.bind(this),s=this.add.bind(this);return function(i,r,n){const o=n.value;return t=t||r,n.value=function(...i){const r=e(t);if(r)return r;return s(o.apply(this,i),t)},n}}GetOrCreateDecorator(t=""){return this.WaitForMe(t)}_onStop(){this.options.onStop&&!this.isLoaded&&this.options.onStop()}}const s=(t,e,s,i)=>{try{t(s(i))}catch(t){e(t)}};let i=0;class r{constructor(e){this.id=i++,this._isCanceled=!1,this._isPending=!0,this._cancelHandlers=[],this._children=[],this._cancelPromise=new Promise((e,s)=>{this._setCanceledCallback=s=>e(s||new t)}),this._promise=Promise.race([this._cancelPromise,new Promise((t,s)=>e(e=>{e instanceof r?this.attach(e):this._isPending=!1,t(e)},t=>{this._isPending=!1,s(t)},t=>{if(!this._isPending)throw new Error("The `onCancel` handler was attached after the promise settled.");this._cancelHandlers.push(t)}))])}static createControl(t){return new e(t)}static resolve(t){return new r(e=>e(t))}static reject(t){return new r((e,s)=>s(t))}static all(t){return new r((e,s)=>{Promise.all(t).then(e).catch(s)})}attach(t){this._isCanceled?t.cancel():this._children.push(t)}then(t,e){const i=new r((i,r)=>{if(this._promise){const n=t=>{e?s(i,r,e,t):r(t)};this._promise.then(e=>{this._isCanceled?n(e):t?s(i,r,t,e):i(e)},n)}});return i._parentPromise=this,this._children.push(i),i}catch(e){return this._isCanceled&&e&&e(new t),this.then(void 0,e)}finally(e){return this._promise?this._promise.finally(e):Promise.reject(this._isCanceled?new t:e)}cancel(){if(this._isCanceled)return this;this._isCanceled=!0;const t=this._getTopParent();if(t&&t.cancel(),this._children&&this._children.forEach(t=>t.cancel()),this._isPending){if(this._cancelHandlers.length)try{for(const t of this._cancelHandlers)t()}catch(t){}this._setCanceledCallback&&this._setCanceledCallback()}return this._destroy(),this}_getTopParent(){let t=this._parentPromise,e=!!t;for(;e;)t&&t._parentPromise?(t=t._parentPromise,e=!!t):e=!1;return t}_destroy(){this._setCanceledCallback=void 0,this._cancelPromise=void 0,this._promise=void 0}}r.CancelError=t,Object.setPrototypeOf(r.prototype,Promise.prototype);export default r;

@@ -1,2 +0,2 @@

/** Bundle of @nextgis/cancelable-promise; version: 1.0.0-alpha.9; author: NextGIS */
/** Bundle of @nextgis/cancelable-promise; version: 1.0.0-alpha.10; author: NextGIS */
/**

@@ -56,3 +56,3 @@ * Thrown when consumer tries to connect when he already connected.

}
GetOrCreateDecorator(name = '') {
WaitForMe(name = '') {
const get = this.get.bind(this);

@@ -74,2 +74,6 @@ const add = this.add.bind(this);

}
/** @deprecated use {@link PromiseControl.WaitForMe } instead */
GetOrCreateDecorator(name = '') {
return this.WaitForMe(name);
}
_onStop() {

@@ -76,0 +80,0 @@ if (this.options.onStop && !this.isLoaded) {

@@ -1,1 +0,1 @@

class t extends Error{constructor(){super(),this.name="CancelError",Object.setPrototypeOf(this,t.prototype)}}class e{constructor(t={}){this.options=t,this._promises=new Map}get isLoaded(){return this._promises.size>0}remove(t){this._promises.has(t)&&(this._promises.delete(t),this._onStop())}get(t){return this._promises.get(t)}add(t,e){const s=e||t,i=this._promises.get(s);return this.options.onStart&&!this.isLoaded&&this.options.onStart(),i||(this._promises.set(s,t),t.finally(()=>{this.remove(s)}),t)}abort(){this.isLoaded&&(this._promises.forEach(t=>{t.cancel&&t.cancel()}),this._promises.clear(),this._onStop())}GetOrCreateDecorator(t=""){const e=this.get.bind(this),s=this.add.bind(this);return function(i,r,n){const o=n.value;return t=t||r,n.value=function(...i){const r=e(t);if(r)return r;return s(o.apply(this,i),t)},n}}_onStop(){this.options.onStop&&!this.isLoaded&&this.options.onStop()}}const s=(t,e,s,i)=>{try{t(s(i))}catch(t){e(t)}};let i=0;class r{constructor(e){this.id=i++,this._isCanceled=!1,this._isPending=!0,this._cancelHandlers=[],this._children=[],this._cancelPromise=new Promise((e,s)=>{this._setCanceledCallback=s=>e(s||new t)}),this._promise=Promise.race([this._cancelPromise,new Promise((t,s)=>e(e=>{e instanceof r?this.attach(e):this._isPending=!1,t(e)},t=>{this._isPending=!1,s(t)},t=>{if(!this._isPending)throw new Error("The `onCancel` handler was attached after the promise settled.");this._cancelHandlers.push(t)}))])}static createControl(t){return new e(t)}static resolve(t){return new r(e=>e(t))}static reject(t){return new r((e,s)=>s(t))}static all(t){return new r((e,s)=>{Promise.all(t).then(e).catch(s)})}attach(t){this._isCanceled?t.cancel():this._children.push(t)}then(t,e){const i=new r((i,r)=>{if(this._promise){const n=t=>{e?s(i,r,e,t):r(t)};this._promise.then(e=>{this._isCanceled?n(e):t?s(i,r,t,e):i(e)},n)}});return i._parentPromise=this,this._children.push(i),i}catch(e){return this._isCanceled&&e&&e(new t),this.then(void 0,e)}finally(e){return this._promise?this._promise.finally(e):Promise.reject(this._isCanceled?new t:e)}cancel(){if(this._isCanceled)return this;this._isCanceled=!0;const t=this._getTopParent();if(t&&t.cancel(),this._children&&this._children.forEach(t=>t.cancel()),this._isPending){if(this._cancelHandlers.length)try{for(const t of this._cancelHandlers)t()}catch(t){}this._setCanceledCallback&&this._setCanceledCallback()}return this._destroy(),this}_getTopParent(){let t=this._parentPromise,e=!!t;for(;e;)t&&t._parentPromise?(t=t._parentPromise,e=!!t):e=!1;return t}_destroy(){this._setCanceledCallback=void 0,this._cancelPromise=void 0,this._promise=void 0}}r.CancelError=t,Object.setPrototypeOf(r.prototype,Promise.prototype);export default r;
class t extends Error{constructor(){super(),this.name="CancelError",Object.setPrototypeOf(this,t.prototype)}}class e{constructor(t={}){this.options=t,this._promises=new Map}get isLoaded(){return this._promises.size>0}remove(t){this._promises.has(t)&&(this._promises.delete(t),this._onStop())}get(t){return this._promises.get(t)}add(t,e){const s=e||t,i=this._promises.get(s);return this.options.onStart&&!this.isLoaded&&this.options.onStart(),i||(this._promises.set(s,t),t.finally(()=>{this.remove(s)}),t)}abort(){this.isLoaded&&(this._promises.forEach(t=>{t.cancel&&t.cancel()}),this._promises.clear(),this._onStop())}WaitForMe(t=""){const e=this.get.bind(this),s=this.add.bind(this);return function(i,r,n){const o=n.value;return t=t||r,n.value=function(...i){const r=e(t);if(r)return r;return s(o.apply(this,i),t)},n}}GetOrCreateDecorator(t=""){return this.WaitForMe(t)}_onStop(){this.options.onStop&&!this.isLoaded&&this.options.onStop()}}const s=(t,e,s,i)=>{try{t(s(i))}catch(t){e(t)}};let i=0;class r{constructor(e){this.id=i++,this._isCanceled=!1,this._isPending=!0,this._cancelHandlers=[],this._children=[],this._cancelPromise=new Promise((e,s)=>{this._setCanceledCallback=s=>e(s||new t)}),this._promise=Promise.race([this._cancelPromise,new Promise((t,s)=>e(e=>{e instanceof r?this.attach(e):this._isPending=!1,t(e)},t=>{this._isPending=!1,s(t)},t=>{if(!this._isPending)throw new Error("The `onCancel` handler was attached after the promise settled.");this._cancelHandlers.push(t)}))])}static createControl(t){return new e(t)}static resolve(t){return new r(e=>e(t))}static reject(t){return new r((e,s)=>s(t))}static all(t){return new r((e,s)=>{Promise.all(t).then(e).catch(s)})}attach(t){this._isCanceled?t.cancel():this._children.push(t)}then(t,e){const i=new r((i,r)=>{if(this._promise){const n=t=>{e?s(i,r,e,t):r(t)};this._promise.then(e=>{this._isCanceled?n(e):t?s(i,r,t,e):i(e)},n)}});return i._parentPromise=this,this._children.push(i),i}catch(e){return this._isCanceled&&e&&e(new t),this.then(void 0,e)}finally(e){return this._promise?this._promise.finally(e):Promise.reject(this._isCanceled?new t:e)}cancel(){if(this._isCanceled)return this;this._isCanceled=!0;const t=this._getTopParent();if(t&&t.cancel(),this._children&&this._children.forEach(t=>t.cancel()),this._isPending){if(this._cancelHandlers.length)try{for(const t of this._cancelHandlers)t()}catch(t){}this._setCanceledCallback&&this._setCanceledCallback()}return this._destroy(),this}_getTopParent(){let t=this._parentPromise,e=!!t;for(;e;)t&&t._parentPromise?(t=t._parentPromise,e=!!t):e=!1;return t}_destroy(){this._setCanceledCallback=void 0,this._cancelPromise=void 0,this._promise=void 0}}r.CancelError=t,Object.setPrototypeOf(r.prototype,Promise.prototype);export default r;

@@ -1,2 +0,2 @@

/** Bundle of @nextgis/cancelable-promise; version: 1.0.0-alpha.9; author: NextGIS */
/** Bundle of @nextgis/cancelable-promise; version: 1.0.0-alpha.10; author: NextGIS */
var CancelablePromise = (function () {

@@ -97,3 +97,3 @@ 'use strict';

};
PromiseControl.prototype.GetOrCreateDecorator = function (name) {
PromiseControl.prototype.WaitForMe = function (name) {
if (name === void 0) { name = ''; }

@@ -120,2 +120,7 @@ var get = this.get.bind(this);

};
/** @deprecated use {@link PromiseControl.WaitForMe } instead */
PromiseControl.prototype.GetOrCreateDecorator = function (name) {
if (name === void 0) { name = ''; }
return this.WaitForMe(name);
};
PromiseControl.prototype._onStop = function () {

@@ -122,0 +127,0 @@ if (this.options.onStop && !this.isLoaded) {

@@ -15,2 +15,2 @@ var CancelablePromise=function(){"use strict";

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(e,n)};var e=function(e){function n(){var t=e.call(this)||this;return t.name="CancelError",Object.setPrototypeOf(t,n.prototype),t}return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}(n,e),n}(Error),n=function(){function t(t){void 0===t&&(t={}),this.options=t,this._promises=new Map}return Object.defineProperty(t.prototype,"isLoaded",{get:function(){return this._promises.size>0},enumerable:!1,configurable:!0}),t.prototype.remove=function(t){this._promises.has(t)&&(this._promises.delete(t),this._onStop())},t.prototype.get=function(t){return this._promises.get(t)},t.prototype.add=function(t,e){var n=this,i=e||t,r=this._promises.get(i);return this.options.onStart&&!this.isLoaded&&this.options.onStart(),r||(this._promises.set(i,t),t.finally((function(){n.remove(i)})),t)},t.prototype.abort=function(){this.isLoaded&&(this._promises.forEach((function(t){t.cancel&&t.cancel()})),this._promises.clear(),this._onStop())},t.prototype.GetOrCreateDecorator=function(t){void 0===t&&(t="");var e=this.get.bind(this),n=this.add.bind(this);return function(i,r,o){var s=o.value;return t=t||r,o.value=function(){for(var i=[],r=0;r<arguments.length;r++)i[r]=arguments[r];var o=e(t);if(o)return o;var c=n(s.apply(this,i),t);return c},o}},t.prototype._onStop=function(){this.options.onStop&&!this.isLoaded&&this.options.onStop()},t}(),i=function(t,e,n,i){try{t(n(i))}catch(t){e(t)}},r=0,o=function(){function t(n){var i=this;this.id=r++,this._isCanceled=!1,this._isPending=!0,this._cancelHandlers=[],this._children=[],this._cancelPromise=new Promise((function(t,n){i._setCanceledCallback=function(n){return t(n||new e)}})),this._promise=Promise.race([this._cancelPromise,new Promise((function(e,r){return n((function(n){n instanceof t?i.attach(n):i._isPending=!1,e(n)}),(function(t){i._isPending=!1,r(t)}),(function(t){if(!i._isPending)throw new Error("The `onCancel` handler was attached after the promise settled.");i._cancelHandlers.push(t)}))}))])}return t.createControl=function(t){return new n(t)},t.resolve=function(e){return new t((function(t){return t(e)}))},t.reject=function(e){return new t((function(t,n){return n(e)}))},t.all=function(e){return new t((function(t,n){Promise.all(e).then(t).catch(n)}))},t.prototype.attach=function(t){this._isCanceled?t.cancel():this._children.push(t)},t.prototype.then=function(e,n){var r=this,o=new t((function(t,o){if(r._promise){var s=function(e){n?i(t,o,n,e):o(e)};r._promise.then((function(n){r._isCanceled?s(n):e?i(t,o,e,n):t(n)}),s)}}));return o._parentPromise=this,this._children.push(o),o},t.prototype.catch=function(t){return this._isCanceled&&t&&t(new e),this.then(void 0,t)},t.prototype.finally=function(t){return this._promise?this._promise.finally(t):Promise.reject(this._isCanceled?new e:t)},t.prototype.cancel=function(){if(this._isCanceled)return this;this._isCanceled=!0;var t=this._getTopParent();if(t&&t.cancel(),this._children&&this._children.forEach((function(t){return t.cancel()})),this._isPending){if(this._cancelHandlers.length)try{for(var e=0,n=this._cancelHandlers;e<n.length;e++){(0,n[e])()}}catch(t){}this._setCanceledCallback&&this._setCanceledCallback()}return this._destroy(),this},t.prototype._getTopParent=function(){for(var t=this._parentPromise,e=!!t;e;)e=!(!t||!t._parentPromise)&&!!(t=t._parentPromise);return t},t.prototype._destroy=function(){this._setCanceledCallback=void 0,this._cancelPromise=void 0,this._promise=void 0},t.CancelError=e,t}();return Object.setPrototypeOf(o.prototype,Promise.prototype),o}();
***************************************************************************** */var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(e,n)};var e=function(e){function n(){var t=e.call(this)||this;return t.name="CancelError",Object.setPrototypeOf(t,n.prototype),t}return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}(n,e),n}(Error),n=function(){function t(t){void 0===t&&(t={}),this.options=t,this._promises=new Map}return Object.defineProperty(t.prototype,"isLoaded",{get:function(){return this._promises.size>0},enumerable:!1,configurable:!0}),t.prototype.remove=function(t){this._promises.has(t)&&(this._promises.delete(t),this._onStop())},t.prototype.get=function(t){return this._promises.get(t)},t.prototype.add=function(t,e){var n=this,i=e||t,r=this._promises.get(i);return this.options.onStart&&!this.isLoaded&&this.options.onStart(),r||(this._promises.set(i,t),t.finally((function(){n.remove(i)})),t)},t.prototype.abort=function(){this.isLoaded&&(this._promises.forEach((function(t){t.cancel&&t.cancel()})),this._promises.clear(),this._onStop())},t.prototype.WaitForMe=function(t){void 0===t&&(t="");var e=this.get.bind(this),n=this.add.bind(this);return function(i,r,o){var s=o.value;return t=t||r,o.value=function(){for(var i=[],r=0;r<arguments.length;r++)i[r]=arguments[r];var o=e(t);if(o)return o;var c=n(s.apply(this,i),t);return c},o}},t.prototype.GetOrCreateDecorator=function(t){return void 0===t&&(t=""),this.WaitForMe(t)},t.prototype._onStop=function(){this.options.onStop&&!this.isLoaded&&this.options.onStop()},t}(),i=function(t,e,n,i){try{t(n(i))}catch(t){e(t)}},r=0,o=function(){function t(n){var i=this;this.id=r++,this._isCanceled=!1,this._isPending=!0,this._cancelHandlers=[],this._children=[],this._cancelPromise=new Promise((function(t,n){i._setCanceledCallback=function(n){return t(n||new e)}})),this._promise=Promise.race([this._cancelPromise,new Promise((function(e,r){return n((function(n){n instanceof t?i.attach(n):i._isPending=!1,e(n)}),(function(t){i._isPending=!1,r(t)}),(function(t){if(!i._isPending)throw new Error("The `onCancel` handler was attached after the promise settled.");i._cancelHandlers.push(t)}))}))])}return t.createControl=function(t){return new n(t)},t.resolve=function(e){return new t((function(t){return t(e)}))},t.reject=function(e){return new t((function(t,n){return n(e)}))},t.all=function(e){return new t((function(t,n){Promise.all(e).then(t).catch(n)}))},t.prototype.attach=function(t){this._isCanceled?t.cancel():this._children.push(t)},t.prototype.then=function(e,n){var r=this,o=new t((function(t,o){if(r._promise){var s=function(e){n?i(t,o,n,e):o(e)};r._promise.then((function(n){r._isCanceled?s(n):e?i(t,o,e,n):t(n)}),s)}}));return o._parentPromise=this,this._children.push(o),o},t.prototype.catch=function(t){return this._isCanceled&&t&&t(new e),this.then(void 0,t)},t.prototype.finally=function(t){return this._promise?this._promise.finally(t):Promise.reject(this._isCanceled?new e:t)},t.prototype.cancel=function(){if(this._isCanceled)return this;this._isCanceled=!0;var t=this._getTopParent();if(t&&t.cancel(),this._children&&this._children.forEach((function(t){return t.cancel()})),this._isPending){if(this._cancelHandlers.length)try{for(var e=0,n=this._cancelHandlers;e<n.length;e++){(0,n[e])()}}catch(t){}this._setCanceledCallback&&this._setCanceledCallback()}return this._destroy(),this},t.prototype._getTopParent=function(){for(var t=this._parentPromise,e=!!t;e;)e=!(!t||!t._parentPromise)&&!!(t=t._parentPromise);return t},t.prototype._destroy=function(){this._setCanceledCallback=void 0,this._cancelPromise=void 0,this._promise=void 0},t.CancelError=e,t}();return Object.setPrototypeOf(o.prototype,Promise.prototype),o}();

@@ -101,2 +101,4 @@ /**

abort(): void;
WaitForMe(name?: string | symbol): MethodDecorator;
/** @deprecated use {@link PromiseControl.WaitForMe } instead */
GetOrCreateDecorator(name?: string | symbol): MethodDecorator;

@@ -103,0 +105,0 @@ private _onStop;

{
"name": "@nextgis/cancelable-promise",
"version": "1.0.0-alpha.9",
"version": "1.0.0-alpha.10",
"description": "A promise you can stop",

@@ -47,3 +47,3 @@ "main": "index.js",

},
"gitHead": "0acf36cfd6d527f7f1ea5c5243ba231d9547e9a8"
"gitHead": "56a31900735b51dd95e2319e29e96b937d0d7667"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc