stack-promises
Advanced tools
Comparing version
@@ -7,4 +7,5 @@ export declare const isEmptyStackError: (error: Error) => boolean; | ||
add: (task: () => Promise<T>) => any; | ||
stop: () => void; | ||
}; | ||
export default creteStackPromises; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import e from"sequent-promises";const t=new Error("Stack is empty"),s=e=>e===t,r=new Error("Promise is not actual"),n=e=>e===r,o=new Error("stackPromises only works with functions that returns a Promise"),i=()=>{const s=[],n=[],i=({task:e,index:t})=>()=>{let s=(({task:e,index:t})=>{const s=n.find((({task:s,index:r})=>e===s&&t===r));if(s)return s.promise})({task:e,index:t});return s||(s=e(),(({task:e,promise:t,index:s})=>{n.push({task:e,promise:t,index:s})})({promise:s,task:e,index:t})),s},a=()=>0===s.length?Promise.reject(t):new Promise(((t,n)=>{const o=(({resolve:e,reject:t})=>({results:n,isSuccessful:o})=>{if(n.length===s.length){const s=n[n.length-1];o?e(s):t(s)}else t(r)})({resolve:t,reject:n});e(s).then(o).catch(o)}));return a.add=e=>{if("function"!=typeof e)throw o;const t=s.length;return s.push(i({task:e,index:t})),a},a};export{i as default,s as isEmptyStackError,n as isPromiseIsNotActualError,r as promiseIsNotActualError}; | ||
import e from"sequent-promises";const t=new Error("Stack is empty"),s=e=>e===t,n=new Error("Promise is not actual"),r=e=>e===n,o=new Error("stackPromises only works with functions that returns a Promise"),i=()=>{const s=[],r=[],i=({task:e,index:t})=>()=>{let s=(({task:e,index:t})=>{const s=r.find((({task:s,index:n})=>e===s&&t===n));if(s)return s.promise})({task:e,index:t});return s||(s=e(),(({task:e,promise:t,index:s})=>{r.push({task:e,promise:t,index:s})})({promise:s,task:e,index:t})),s};let c=!1;const a=()=>c,l=()=>(c=!0,e(s,a)),u=()=>0===s.length?Promise.reject(t):new Promise(((e,t)=>{const r=(({resolve:e,reject:t})=>({results:r,isSuccessful:o})=>{if(r.length===s.length){const s=r[r.length-1];o?e(s):t(s)}else t(n)})({resolve:e,reject:t});l().then(r).catch(r)}));return u.add=e=>{if("function"!=typeof e)throw o;const t=s.length;return s.push(i({task:e,index:t})),u},u.stop=()=>{c=!1,s.length=0,r.length=0},u};export{i as default,s as isEmptyStackError,r as isPromiseIsNotActualError,n as promiseIsNotActualError}; | ||
//# sourceMappingURL=index.es5.js.map |
@@ -62,4 +62,15 @@ "use strict"; | ||
}; | ||
let isCanRunTasks = false; | ||
const enableRunTasks = () => { | ||
isCanRunTasks = true; | ||
}; | ||
const disableRunTasks = () => { | ||
isCanRunTasks = false; | ||
}; | ||
const canRunTask = () => { | ||
return isCanRunTasks; | ||
}; | ||
const runStackPromises = () => { | ||
return (0, sequent_promises_1.default)(runnersStack); | ||
enableRunTasks(); | ||
return (0, sequent_promises_1.default)(runnersStack, canRunTask); | ||
}; | ||
@@ -83,3 +94,12 @@ const result = () => { | ||
}; | ||
const clearStacks = () => { | ||
runnersStack.length = 0; | ||
tasksStack.length = 0; | ||
}; | ||
const stop = () => { | ||
disableRunTasks(); | ||
clearStacks(); | ||
}; | ||
result.add = addTaskToStack; | ||
result.stop = stop; | ||
return result; | ||
@@ -86,0 +106,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("sequent-promises")):"function"==typeof define&&define.amd?define(["exports","sequent-promises"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).sipConnector={},e.sequentPromisesList)}(this,(function(e,t){"use strict";function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=s(t);const n=new Error("Stack is empty"),o=new Error("Promise is not actual"),i=new Error("stackPromises only works with functions that returns a Promise");e.default=()=>{const e=[],t=[],s=({task:e,index:s})=>()=>{let r=(({task:e,index:s})=>{const r=t.find((({task:t,index:r})=>e===t&&s===r));if(r)return r.promise})({task:e,index:s});return r||(r=e(),(({task:e,promise:s,index:r})=>{t.push({task:e,promise:s,index:r})})({promise:r,task:e,index:s})),r},u=()=>0===e.length?Promise.reject(n):new Promise(((t,s)=>{const n=(({resolve:t,reject:s})=>({results:r,isSuccessful:n})=>{if(r.length===e.length){const e=r[r.length-1];n?t(e):s(e)}else s(o)})({resolve:t,reject:s});r.default(e).then(n).catch(n)}));return u.add=t=>{if("function"!=typeof t)throw i;const r=e.length;return e.push(s({task:t,index:r})),u},u},e.isEmptyStackError=e=>e===n,e.isPromiseIsNotActualError=e=>e===o,e.promiseIsNotActualError=o,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("sequent-promises")):"function"==typeof define&&define.amd?define(["exports","sequent-promises"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).sipConnector={},e.sequentPromisesList)}(this,(function(e,t){"use strict";const s=new Error("Stack is empty"),r=new Error("Promise is not actual"),n=new Error("stackPromises only works with functions that returns a Promise");e.default=()=>{const e=[],o=[],i=({task:e,index:t})=>()=>{let s=(({task:e,index:t})=>{const s=o.find((({task:s,index:r})=>e===s&&t===r));if(s)return s.promise})({task:e,index:t});return s||(s=e(),(({task:e,promise:t,index:s})=>{o.push({task:e,promise:t,index:s})})({promise:s,task:e,index:t})),s};let c=!1;const u=()=>c,l=()=>(c=!0,t(e,u)),a=()=>0===e.length?Promise.reject(s):new Promise(((t,s)=>{const n=(({resolve:t,reject:s})=>({results:n,isSuccessful:o})=>{if(n.length===e.length){const e=n[n.length-1];o?t(e):s(e)}else s(r)})({resolve:t,reject:s});l().then(n).catch(n)}));return a.add=t=>{if("function"!=typeof t)throw n;const s=e.length;return e.push(i({task:t,index:s})),a},a.stop=()=>{c=!1,e.length=0,o.length=0},a},e.isEmptyStackError=e=>e===s,e.isPromiseIsNotActualError=e=>e===r,e.promiseIsNotActualError=r,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "stack-promises", | ||
"version": "0.0.8", | ||
"version": "0.0.9", | ||
"description": "sequentPromises resolves Promises sequentially", | ||
@@ -31,8 +31,8 @@ "keywords": [ | ||
"build": "yarn build:ts && yarn build:js", | ||
"build:js": "NODE_ENV=production rollup --config", | ||
"build:js": "NODE_ENV=production rollup --config --bundleConfigAsCjs", | ||
"build:ts": "tsc --build tsconfig.build.json", | ||
"format": "prettier --write \"src/**/*.ts\"", | ||
"lint": "eslint src/. --ext .ts", | ||
"prepare": "npm run build", | ||
"prepublishOnly": "npm test && npm run lint", | ||
"prepare": "yarn build", | ||
"prepublishOnly": "yarn test && yarn lint", | ||
"release": "standard-version", | ||
@@ -45,28 +45,28 @@ "test": "jest" | ||
"devDependencies": { | ||
"@commitlint/cli": "^16.0.2", | ||
"@commitlint/config-conventional": "^16.0.0", | ||
"@rollup/plugin-commonjs": "^21.0.1", | ||
"@rollup/plugin-node-resolve": "^13.1.3", | ||
"@types/jest": "^27.4.0", | ||
"@types/node": "^17.0.9", | ||
"@typescript-eslint/eslint-plugin": "^5.10.0", | ||
"@typescript-eslint/parser": "^5.10.0", | ||
"eslint": "^8.7.0", | ||
"@commitlint/cli": "^17.1.2", | ||
"@commitlint/config-conventional": "^17.1.0", | ||
"@rollup/plugin-commonjs": "^23.0.0", | ||
"@rollup/plugin-node-resolve": "^15.0.0", | ||
"@types/jest": "^29.1.2", | ||
"@types/node": "^18.8.5", | ||
"@typescript-eslint/eslint-plugin": "^5.40.0", | ||
"@typescript-eslint/parser": "^5.40.0", | ||
"eslint": "^8.25.0", | ||
"eslint-config-airbnb": "^19.0.4", | ||
"eslint-config-airbnb-typescript": "16.1.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-import": "^2.25.4", | ||
"eslint-plugin-jest": "^25.7.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"husky": "^7.0.4", | ||
"jest": "27.4.7", | ||
"lint-staged": "^12.1.7", | ||
"prettier": "^2.5.1", | ||
"eslint-config-airbnb-typescript": "17.0.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-jest": "^27.1.1", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"husky": "^8.0.1", | ||
"jest": "29.1.2", | ||
"lint-staged": "^13.0.3", | ||
"prettier": "^2.7.1", | ||
"promise-delay": "^2.1.0", | ||
"rollup": "^2.64.0", | ||
"rollup": "^3.1.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"rollup-plugin-typescript2": "0.31.1", | ||
"standard-version": "^9.3.2", | ||
"ts-jest": "^27.1.3", | ||
"typescript": "^4.5.4" | ||
"rollup-plugin-typescript2": "0.34.1", | ||
"standard-version": "^9.5.0", | ||
"ts-jest": "^29.0.3", | ||
"typescript": "^4.8.4" | ||
}, | ||
@@ -73,0 +73,0 @@ "main:src": "src/index.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
27104
10.24%126
20%4
33.33%