Comparing version 1.1.7 to 1.2.0
@@ -0,1 +1,6 @@ | ||
## [1.2.0](https://github.com/qiwi/queuefy/compare/v1.1.7...v1.2.0) (2023-03-19) | ||
### Features | ||
* feat: introduce concurrency opt ([2ce7e83](https://github.com/qiwi/queuefy/commit/2ce7e83cbae3e035ff28603ac928ea679d548b42)) | ||
## [1.1.7](https://github.com/qiwi/queuefy/compare/v1.1.6...v1.1.7) (2022-11-19) | ||
@@ -2,0 +7,0 @@ |
/** | ||
* Flowtype definitions for index | ||
* Generated by Flowgen from a Typescript Definition | ||
* Flowgen v1.19.0 | ||
* Flowgen v1.20.1 | ||
*/ | ||
declare module "queuefy" { | ||
declare export * from "queuefy/target/es6"; | ||
} | ||
declare module "queuefy/target/es5" { | ||
import type { ICallable } from "@qiwi/substrate"; | ||
declare export type TInsideOutPromise = { | ||
promise: Promise<any>, | ||
resolve: ICallable, | ||
reject: ICallable, | ||
... | ||
}; | ||
declare export type IAsyncFn = (...args: any[]) => Promise<any>; | ||
declare export type ITask = { | ||
args: any[], | ||
iop: TInsideOutPromise, | ||
... | ||
}; | ||
declare export type ITaskQueue = Array<ITask>; | ||
/** | ||
* TODO implement lightweight version of 'inside-out-promise' | ||
* @private | ||
*/ | ||
declare export var getPromise: () => TInsideOutPromise; | ||
/** | ||
* @private | ||
* @param target | ||
*/ | ||
declare export var isPromiseLike: (target: any) => boolean; | ||
declare export var compose: ( | ||
cb: ICallable, | ||
next: ICallable | ||
) => <V>(v: V) => void; | ||
declare export var invoke: ( | ||
fn: IAsyncFn, | ||
task: ITask, | ||
next: ICallable | ||
) => void; | ||
declare export var queuefy: <T: IAsyncFn>(fn: T) => T; | ||
} | ||
declare module "queuefy/target/es6" { | ||
import type { ICallable } from "@qiwi/substrate"; | ||
declare export type TInsideOutPromise = { | ||
promise: Promise<any>, | ||
resolve: ICallable, | ||
reject: ICallable, | ||
... | ||
}; | ||
declare export type IAsyncFn = (...args: any[]) => Promise<any>; | ||
declare export type ITask = { | ||
args: any[], | ||
iop: TInsideOutPromise, | ||
... | ||
}; | ||
declare export type ITaskQueue = Array<ITask>; | ||
/** | ||
* TODO implement lightweight version of 'inside-out-promise' | ||
* @private | ||
*/ | ||
declare export var getPromise: () => TInsideOutPromise; | ||
/** | ||
* @private | ||
* @param target | ||
*/ | ||
declare export var isPromiseLike: (target: any) => boolean; | ||
declare export var compose: ( | ||
cb: ICallable, | ||
next: ICallable | ||
) => <V>(v: V) => void; | ||
declare export var invoke: ( | ||
fn: IAsyncFn, | ||
task: ITask, | ||
next: ICallable | ||
) => void; | ||
declare export var queuefy: <T: IAsyncFn>(fn: T) => T; | ||
} | ||
import { ICallable } from "@qiwi/substrate"; | ||
export type TInsideOutPromise = { | ||
promise: Promise<any>, | ||
resolve: ICallable, | ||
reject: ICallable, | ||
... | ||
}; | ||
export type IAsyncFn = (...args: any[]) => Promise<any>; | ||
export type ITask = { | ||
args: any[], | ||
iop: TInsideOutPromise, | ||
... | ||
}; | ||
export type ITaskQueue = Array<ITask>; | ||
/** | ||
* TODO implement lightweight version of 'inside-out-promise' | ||
* @private | ||
*/ | ||
declare export var getPromise: () => TInsideOutPromise; | ||
/** | ||
* @private | ||
* @param target | ||
*/ | ||
declare export var isPromiseLike: (target: any) => boolean; | ||
declare export var compose: ( | ||
cb: ICallable, | ||
next: ICallable | ||
) => <V>(v: V) => void; | ||
declare export var invoke: (fn: IAsyncFn, task: ITask, next: ICallable) => void; | ||
declare export var queuefy: <T: IAsyncFn>(fn: T, limit?: number) => T; |
{ | ||
"name": "queuefy", | ||
"alias": "@qiwi/queuefy", | ||
"version": "1.1.7", | ||
"version": "1.2.0", | ||
"private": false, | ||
@@ -23,6 +23,5 @@ "description": "Wrapper to make any async handler be like a single thread with queue", | ||
"test:deps": "npm-run-all -p -l test:depcheck test:depauditfix", | ||
"test:depcheck": "npx depcheck --ignores tslib,@swissquote/crafty-preset-jest,@types/jest,typedoc,@types/node", | ||
"test:depcheck": "npx depcheck --ignores mkdirp,rimraf,tslib,@swissquote/crafty-preset-jest,@types/jest,typedoc,@types/node", | ||
"test:depaudit": "yarn audit --level=moderate; [[ $? -ge 4 ]] && exit 1 || exit 0", | ||
"test:depauditfix": "npx yarn-audit-fix --audit-level=moderate", | ||
"test:report": "yarn test && yarn push:report", | ||
"build": "yarn clean && npm-run-all -p -l build:es5 build:es6 build:ts build:libdef build:bundle docs", | ||
@@ -35,4 +34,2 @@ "build:es5": "mkdirp target/es5 && tsc -p tsconfig.es5.json", | ||
"docs": "typedoc --options ./typedoc.json ./src/main/ts", | ||
"coveralls:push": "cat ./coverage/lcov.info | coveralls || exit 0", | ||
"push:report": "yarn coveralls:push", | ||
"uglify": "for f in $(find target -name '*.js'); do short=${f%.js}; terser -c -m -o $short.js -- $f; done", | ||
@@ -59,24 +56,23 @@ "postupdate": "yarn && yarn test:deps && yarn build && yarn test" | ||
"devDependencies": { | ||
"@qiwi/libdefkit": "^4.0.8", | ||
"@qiwi/libdefkit": "^5.0.0", | ||
"@qiwi/npm-run-all": "^4.1.7", | ||
"@types/jest": "^29.2.2", | ||
"@types/node": "^18.11.9", | ||
"coveralls": "^3.1.1", | ||
"jest": "^29.2.2", | ||
"@types/jest": "^29.5.0", | ||
"@types/node": "^18.15.3", | ||
"jest": "^29.5.0", | ||
"microbundle": "^0.15.1", | ||
"mkdirp": "^1.0.4", | ||
"rimraf": "^3.0.2", | ||
"terser": "^5.15.1", | ||
"mkdirp": "^2.1.5", | ||
"rimraf": "^4.4.0", | ||
"terser": "^5.16.6", | ||
"cpy-cli": "^4.2.0", | ||
"eslint": "^8.27.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-config-qiwi": "^1.17.8", | ||
"typedoc": "^0.23.20", | ||
"typescript": "4.9.3", | ||
"ts-jest": "^29.0.3" | ||
"eslint": "^8.36.0", | ||
"eslint-config-prettier": "^8.7.0", | ||
"eslint-config-qiwi": "^2.1.1", | ||
"typedoc": "^0.23.28", | ||
"typescript": "5.0.2", | ||
"ts-jest": "^29.0.5" | ||
}, | ||
"dependencies": { | ||
"tslib": "^2.4.1", | ||
"@qiwi/substrate": "^1.20.15" | ||
"tslib": "^2.5.0", | ||
"@qiwi/substrate": "^2.0.3" | ||
} | ||
} |
@@ -7,3 +7,3 @@ # queuefy | ||
Wrapper to make any async handler be like a single thread with a queue. | ||
Wrapper to make any async handler act like a single thread with a queue. | ||
@@ -10,0 +10,0 @@ ## Install |
@@ -1,2 +0,2 @@ | ||
var e=function(){var e={};return e.promise=new Promise(function(n,r){e.resolve=n,e.reject=r}),e},n=function(e){return!!e&&"function"==typeof e.then&&"function"==typeof e.catch},r=function(e,n){return function(r){e(r),n()}},t=function(e,t,o){var i=t.iop,c=t.args,u=r(i.resolve,o),s=r(i.reject,o);try{var f=e.apply(void 0,c);n(f)?f.then(u,s):u(f)}catch(e){s(e)}};exports.compose=r,exports.getPromise=e,exports.invoke=t,exports.isPromiseLike=n,exports.queuefy=function(n){var r=[],o=function(){var e=r[0];e&&t(n,e,i)},i=function(){r.shift(),o()};return function(){var n=e();return r.push({args:[].slice.call(arguments),iop:n}),1===r.length&&o(),n.promise}}; | ||
var e=function(){var e={};return e.promise=new Promise(function(r,n){e.resolve=r,e.reject=n}),e},r=function(e){return!!e&&"function"==typeof e.then&&"function"==typeof e.catch},n=function(e,r){return function(n){e(n),r()}},o=function(e,o,t){var i=o.iop,c=o.args,u=n(i.resolve,t),s=n(i.reject,t);try{var f=e.apply(void 0,c);r(f)?f.then(u,s):u(f)}catch(e){s(e)}};exports.compose=n,exports.getPromise=e,exports.invoke=o,exports.isPromiseLike=r,exports.queuefy=function(r,n){void 0===n&&(n=1);var t=[],i=function e(){if(0!==n){var i=t.shift();i&&(n--,o(r,i,function(){n++,e()}))}};return function(){var r=e();return t.push({args:[].slice.call(arguments),iop:r}),i(),r.promise}}; | ||
//# sourceMappingURL=queuefy.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).queuefy={})}(this,function(e){var n=function(){var e={};return e.promise=new Promise(function(n,o){e.resolve=n,e.reject=o}),e},o=function(e){return!!e&&"function"==typeof e.then&&"function"==typeof e.catch},t=function(e,n){return function(o){e(o),n()}},i=function(e,n,i){var r=n.iop,f=n.args,u=t(r.resolve,i),c=t(r.reject,i);try{var s=e.apply(void 0,f);o(s)?s.then(u,c):u(s)}catch(e){c(e)}};e.compose=t,e.getPromise=n,e.invoke=i,e.isPromiseLike=o,e.queuefy=function(e){var o=[],t=function(){var n=o[0];n&&i(e,n,r)},r=function(){o.shift(),t()};return function(){var e=n();return o.push({args:[].slice.call(arguments),iop:e}),1===o.length&&t(),e.promise}}}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e||self).queuefy={})}(this,function(e){var n=function(){var e={};return e.promise=new Promise(function(n,o){e.resolve=n,e.reject=o}),e},o=function(e){return!!e&&"function"==typeof e.then&&"function"==typeof e.catch},t=function(e,n){return function(o){e(o),n()}},i=function(e,n,i){var r=n.iop,f=n.args,u=t(r.resolve,i),c=t(r.reject,i);try{var s=e.apply(void 0,f);o(s)?s.then(u,c):u(s)}catch(e){c(e)}};e.compose=t,e.getPromise=n,e.invoke=i,e.isPromiseLike=o,e.queuefy=function(e,o){void 0===o&&(o=1);var t=[],r=function n(){if(0!==o){var r=t.shift();r&&(o--,i(e,r,function(){o++,n()}))}};return function(){var e=n();return t.push({args:[].slice.call(arguments),iop:e}),r(),e.promise}}}); | ||
//# sourceMappingURL=queuefy.umd.js.map |
@@ -25,2 +25,2 @@ import { ICallable } from '@qiwi/substrate'; | ||
export declare const invoke: (fn: IAsyncFn, task: ITask, next: ICallable) => void; | ||
export declare const queuefy: <T extends IAsyncFn>(fn: T) => T; | ||
export declare const queuefy: <T extends IAsyncFn>(fn: T, limit?: number) => T; |
@@ -43,15 +43,19 @@ /** | ||
}; | ||
export var queuefy = function (fn) { | ||
export var queuefy = function (fn, limit) { | ||
if (limit === void 0) { limit = 1; } | ||
var queue = []; | ||
var processQueue = function () { | ||
var task = queue[0]; | ||
if (limit === 0) { | ||
return; | ||
} | ||
var task = queue.shift(); | ||
if (!task) { | ||
return; | ||
} | ||
invoke(fn, task, next); | ||
limit--; | ||
invoke(fn, task, function () { | ||
limit++; | ||
processQueue(); | ||
}); | ||
}; | ||
var next = function () { | ||
queue.shift(); | ||
processQueue(); | ||
}; | ||
return (function () { | ||
@@ -64,7 +68,5 @@ var args = []; | ||
queue.push({ args: args, iop: iop }); | ||
if (queue.length === 1) { | ||
processQueue(); | ||
} | ||
processQueue(); | ||
return iop.promise; | ||
}); | ||
}; |
@@ -25,2 +25,2 @@ import { ICallable } from '@qiwi/substrate'; | ||
export declare const invoke: (fn: IAsyncFn, task: ITask, next: ICallable) => void; | ||
export declare const queuefy: <T extends IAsyncFn>(fn: T) => T; | ||
export declare const queuefy: <T extends IAsyncFn>(fn: T, limit?: number) => T; |
@@ -41,23 +41,24 @@ /** | ||
}; | ||
export const queuefy = (fn) => { | ||
export const queuefy = (fn, limit = 1) => { | ||
const queue = []; | ||
const processQueue = () => { | ||
const task = queue[0]; | ||
if (limit === 0) { | ||
return; | ||
} | ||
const task = queue.shift(); | ||
if (!task) { | ||
return; | ||
} | ||
invoke(fn, task, next); | ||
limit--; | ||
invoke(fn, task, () => { | ||
limit++; | ||
processQueue(); | ||
}); | ||
}; | ||
const next = () => { | ||
queue.shift(); | ||
processQueue(); | ||
}; | ||
return ((...args) => { | ||
const iop = getPromise(); | ||
queue.push({ args, iop }); | ||
if (queue.length === 1) { | ||
processQueue(); | ||
} | ||
processQueue(); | ||
return iop.promise; | ||
}); | ||
}; |
@@ -68,7 +68,10 @@ import { | ||
export const queuefy = <T extends IAsyncFn>(fn: T): T => { | ||
export const queuefy = <T extends IAsyncFn>(fn: T, limit = 1): T => { | ||
const queue: ITaskQueue = [] | ||
const processQueue = (): void => { | ||
const task = queue[0] | ||
if (limit === 0) { | ||
return | ||
} | ||
const task = queue.shift() | ||
if (!task) { | ||
@@ -78,8 +81,8 @@ return | ||
invoke(fn, task, next) | ||
limit-- | ||
invoke(fn, task, () => { | ||
limit++ | ||
processQueue() | ||
}) | ||
} | ||
const next = () => { | ||
queue.shift() | ||
processQueue() | ||
} | ||
@@ -90,9 +93,6 @@ return ((...args: any[]): any => { | ||
queue.push({args, iop}) | ||
processQueue() | ||
if (queue.length === 1) { | ||
processQueue() | ||
} | ||
return iop.promise | ||
}) as T | ||
} |
@@ -25,2 +25,2 @@ import { ICallable } from '@qiwi/substrate'; | ||
export declare const invoke: (fn: IAsyncFn, task: ITask, next: ICallable) => void; | ||
export declare const queuefy: <T extends IAsyncFn>(fn: T) => T; | ||
export declare const queuefy: <T extends IAsyncFn>(fn: T, limit?: number) => T; |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16
30261
338
+ Added@qiwi/substrate@2.1.0(transitive)
+ Added@qiwi/substrate-abstract@2.1.0(transitive)
+ Added@qiwi/substrate-std@2.1.0(transitive)
+ Added@qiwi/substrate-types@2.1.0(transitive)
- Removed@qiwi/substrate@1.20.17(transitive)
- Removed@qiwi/substrate-abstract@1.20.11(transitive)
- Removed@qiwi/substrate-std@1.3.12(transitive)
- Removed@qiwi/substrate-types@2.0.0(transitive)
Updated@qiwi/substrate@^2.0.3
Updatedtslib@^2.5.0