vanilla-queues-js
Advanced tools
| /** | ||
| * @param data get data when pass before execution r | ||
| * @param counter job count execution by queue machine runJobs | ||
| */ | ||
| interface queueCallback<returnType> { | ||
| (data: returnType, counter: number): void; | ||
| } | ||
| interface IVanillaQueues<returnType> { | ||
| /** | ||
| * total count index start from 0 | ||
| */ | ||
| queueCount: number; | ||
| /** | ||
| * calculate pause count... | ||
| */ | ||
| pauseCount: number; | ||
| /** | ||
| * grobal array to mark as complete all jobs | ||
| * @param callback an evert is on succes | ||
| */ | ||
| isDone(callback: () => void): void; | ||
| /** | ||
| * | ||
| * @param callback as call back basses of transfer | ||
| * @param transferData callback data ewcive | ||
| */ | ||
| addJob(callback: queueCallback<returnType>, transferData: returnType): void; | ||
| breakCall(callback: () => void, everyNumberJobDone: number): void; | ||
| pause(): void; | ||
| resume(): void; | ||
| stop(): void; | ||
| runJobs(): void; | ||
| jobDone(): void; | ||
| } | ||
| declare class VanillaQueues<returnType> implements IVanillaQueues<returnType> { | ||
| private doneCallback; | ||
| private pauseCallback; | ||
| private queueActual; | ||
| private isPause; | ||
| private _stackJobs; | ||
| constructor(queueCountInit?: number); | ||
| stop(): void; | ||
| breakCall(callback: () => void, everyNumberJobDone: number): void; | ||
| pauseCount: number; | ||
| pause(callback?: () => void): void; | ||
| resume(): void; | ||
| addJob(callback: queueCallback<returnType>, transferData: returnType): void; | ||
| /** | ||
| * name | ||
| */ | ||
| runJobs(): void; | ||
| jobDone(): void; | ||
| isDone(callback: () => void): void; | ||
| private _queueCount; | ||
| get queueCount(): number; | ||
| set queueCount(value: number); | ||
| } | ||
| export { VanillaQueues, queueCallback, IVanillaQueues }; | ||
| //# sourceMappingURL=index.d.ts.map |
| {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,UAAU,aAAa,CAAC,UAAU;IAC9B,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAC5C;AAED,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IzC,OAAO,CAAC,WAAW,CAAS;IAE5B,IAAW,UAAU,IAAI,MAAM,CAE9B;IACD,IAAW,UAAU,CAAC,KAAK,EAAE,MAAM,EAElC;CAGJ;AAED,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.VanillaQueues = void 0; | ||
| var VanillaQueues = /** @class */ (function () { | ||
| function VanillaQueues(queueCountInit) { | ||
| this.doneCallback = function () { }; | ||
| this.pauseCallback = function () { }; | ||
| this.queueActual = 0; | ||
| this.isPause = false; | ||
| this.pauseCount = 0; | ||
| if (queueCountInit && parseInt(queueCountInit.toString()) >= 1) | ||
| this._queueCount = queueCountInit; | ||
| else | ||
| this._queueCount = 5; | ||
| this._stackJobs = []; | ||
| } | ||
| VanillaQueues.prototype.stop = function () { | ||
| this._stackJobs = []; | ||
| this.queueActual = 0; | ||
| }; | ||
| VanillaQueues.prototype.breakCall = function (callback, everyNumberJobDone) { | ||
| if (!everyNumberJobDone) | ||
| throw new Error("Method not implemented."); | ||
| }; | ||
| VanillaQueues.prototype.pause = function (callback) { | ||
| if (callback) | ||
| this.pauseCallback = callback; | ||
| this.isPause = true; | ||
| }; | ||
| VanillaQueues.prototype.resume = function () { | ||
| this.isPause = false; | ||
| for (var index = this.pauseCount; index > 0; index--) | ||
| this.jobDone(); | ||
| this.pauseCount = 0; | ||
| }; | ||
| VanillaQueues.prototype.addJob = function (callback, transferData) { | ||
| this._stackJobs.push({ callback: callback, data: transferData }); | ||
| }; | ||
| /** | ||
| * name | ||
| */ | ||
| VanillaQueues.prototype.runJobs = function () { | ||
| if (this._stackJobs.length <= this._queueCount) | ||
| this._queueCount = this._stackJobs.length; | ||
| this._stackJobs = this._stackJobs.reverse(); | ||
| this.queueActual = this._queueCount; | ||
| for (var index = 0; index < this._queueCount; index++) { | ||
| var runInstance = this._stackJobs.pop(); | ||
| runInstance === null || runInstance === void 0 ? void 0 : runInstance.callback(runInstance.data, index); | ||
| } | ||
| }; | ||
| VanillaQueues.prototype.jobDone = function () { | ||
| if (!this.isPause) { | ||
| if (this._stackJobs.length !== 0) { | ||
| var runInstance = this._stackJobs.pop(); | ||
| runInstance === null || runInstance === void 0 ? void 0 : runInstance.callback(runInstance.data, this._queueCount++); | ||
| } | ||
| else if (--this.queueActual === 0) | ||
| this.doneCallback(); | ||
| } | ||
| else if (this.queueActual == ++this.pauseCount) | ||
| this.pauseCallback(); | ||
| }; | ||
| VanillaQueues.prototype.isDone = function (callback) { | ||
| this.doneCallback = callback; | ||
| }; | ||
| Object.defineProperty(VanillaQueues.prototype, "queueCount", { | ||
| get: function () { | ||
| return this._queueCount; | ||
| }, | ||
| set: function (value) { | ||
| this._queueCount = value; | ||
| }, | ||
| enumerable: false, | ||
| configurable: true | ||
| }); | ||
| return VanillaQueues; | ||
| }()); | ||
| exports.VanillaQueues = VanillaQueues; | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAyCA;IAYI,uBAAY,cAAuB;QAV3B,iBAAY,GAAe,cAAc,CAAC,CAAC;QAC3C,kBAAa,GAAe,cAAc,CAAC,CAAC;QAC5C,gBAAW,GAAW,CAAC,CAAC;QACxB,YAAO,GAAY,KAAK,CAAC;QAyBjC,eAAU,GAAW,CAAC,CAAC;QAhBnB,IAAI,cAAc,IAAI,QAAQ,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC;YAC1D,IAAI,CAAC,WAAW,GAAG,cAAc,CAAC;;YAElC,IAAI,CAAC,WAAW,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACzB,CAAC;IACD,4BAAI,GAAJ;QACI,IAAI,CAAC,UAAU,GAAC,EAAE,CAAC;QACnB,IAAI,CAAC,WAAW,GAAC,CAAC,CAAC;IACvB,CAAC;IAED,iCAAS,GAAT,UAAU,QA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AEM,+BAAO,GAAd;QACI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACf,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC9B,IAAI,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;gBACxC,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;aAC/D;iBAAM,IAAI,EAAE,IAAI,CAAC,WAAW,KAAK,CAAC;gBAC/B,IAAI,CAAC,YAAY,EAAE,CAAC;SAC3B;aAAM,IAAI,IAAI,CAAC,WAAW,IAAI,EAAE,IAAI,CAAC,UAAU;YAC5C,IAAI,CAAC,aAAa,EAAE,CAAC;IAC7B,CAAC;IAEM,8BAAM,GAAb,UAAc,QAAoB;QAC9B,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC;IACjC,CAAC;IAID,sBAAW,qCAAU;aAArB;YACI,OAAO,IAAI,CAAC,WAAW,CAAC;QAC5B,CAAC;aACD,UAAsB,KAAa;YAC/B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QAC7B,CAAC;;;OAHA;IAML,oBAAC;AAAD,CAAC,AAxFD,IAwFC;AAEQ,sCAAa"} |
| export {}; | ||
| //# sourceMappingURL=test.d.ts.map |
| {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":""} |
+20
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var _1 = require("."); | ||
| var vanilaQue = new _1.VanillaQueues(5); | ||
| for (var index = 0; index < 100; index++) { | ||
| vanilaQue.addJob(function (data, counter) { | ||
| console.log(counter, "****"); | ||
| setTimeout(function () { | ||
| console.log(data, "------> executed ---->", counter); | ||
| vanilaQue.jobDone(); | ||
| }, Math.floor(Math.random() * 3000) + 1000); //Math.floor(Math.random() * 2000) + | ||
| }, index); | ||
| } | ||
| vanilaQue.isDone(function () { | ||
| console.log("oeeeeee done..."); | ||
| }); | ||
| vanilaQue.runJobs(); | ||
| setTimeout(function () { return vanilaQue.pause(function () { return console.log("pause successfully..."); }); }, 10000); | ||
| setTimeout(function () { return vanilaQue.resume(); }, 30000); | ||
| //# sourceMappingURL=test.js.map |
| {"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":";;AAAA,sBAAkC;AAElC,IAAI,SAAS,GAAG,IAAI,gBAAa,CAAS,CAAC,CAAC,CAAC;AAC7C,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,GAAG,EAAE,KAAK,EAAE,EAAE;IACtC,SAAS,CAAC,MAAM,CAAC,UAAC,IAAI,EAAE,OAAO;QAC3B,OAAO,CAAC,GAAG,CAAC,OAAO,EAAC,MAAM,CAAC,CAAC;QAC5B,UAAU,CAAC;YACP,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,wBAAwB,EAAE,OAAO,CAAC,CAAC;YACrD,SAAS,CAAC,OAAO,EAAE,CAAC;QACxB,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA,oCAAoC;IACpF,CAAC,EAAE,KAAK,CAAC,CAAC;CACb;AAED,SAAS,CAAC,MAAM,CAAC;IACb,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAEnC,CAAC,CAAC,CAAC;AAEH,SAAS,CAAC,OAAO,EAAE,CAAC;AAEpB,UAAU,CAAC,cAAI,OAAA,SAAS,CAAC,KAAK,CAAC,cAAI,OAAA,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,EAApC,CAAoC,CACtE,EADc,CACd,EAAC,KAAK,CAAC,CAAC;AAET,UAAU,CAAC,cAAI,OAAA,SAAS,CAAC,MAAM,EAAE,EAAlB,CAAkB,EAAC,KAAK,CAAC,CAAC"} |
+132
| /** | ||
| * @param data get data when pass before execution r | ||
| * @param counter job count execution by queue machine runJobs | ||
| */ | ||
| interface queueCallback<returnType> { | ||
| (data: returnType, counter: number): void | ||
| } | ||
| interface IVanillaQueues<returnType> { | ||
| // myCallback; | ||
| /** | ||
| * total count index start from 0 | ||
| */ | ||
| queueCount: number; | ||
| /** | ||
| * calculate pause count... | ||
| */ | ||
| pauseCount: number; | ||
| /** | ||
| * grobal array to mark as complete all jobs | ||
| * @param callback an evert is on succes | ||
| */ | ||
| isDone(callback: () => void): void; | ||
| /** | ||
| * | ||
| * @param callback as call back basses of transfer | ||
| * @param transferData callback data ewcive | ||
| */ | ||
| addJob(callback: queueCallback<returnType>, transferData: returnType): void; | ||
| breakCall(callback: () => void, everyNumberJobDone: number): void; | ||
| pause(): void; | ||
| resume(): void; | ||
| stop():void; | ||
| runJobs(): void; | ||
| jobDone(): void; | ||
| } | ||
| class VanillaQueues<returnType> implements IVanillaQueues<returnType> { | ||
| private doneCallback: () => void = function () { }; | ||
| private pauseCallback: () => void = function () { }; | ||
| private queueActual: number = 0; | ||
| private isPause: boolean = false; | ||
| // private | ||
| private _stackJobs: { | ||
| callback: queueCallback<returnType>; | ||
| data: returnType; | ||
| }[]; | ||
| constructor(queueCountInit?: number) { | ||
| if (queueCountInit && parseInt(queueCountInit.toString()) >= 1) | ||
| this._queueCount = queueCountInit; | ||
| else | ||
| this._queueCount = 5; | ||
| this._stackJobs = []; | ||
| } | ||
| stop(): void { | ||
| this._stackJobs=[]; | ||
| this.queueActual=0; | ||
| } | ||
| breakCall(callback: () => void, everyNumberJobDone: number): void { | ||
| if (!everyNumberJobDone) | ||
| throw new Error("Method not implemented."); | ||
| } | ||
| pauseCount: number = 0; | ||
| public pause(callback?: () => void): void { | ||
| if (callback) | ||
| this.pauseCallback = callback; | ||
| this.isPause = true; | ||
| } | ||
| public resume(): void { | ||
| this.isPause = false; | ||
| for (let index = this.pauseCount; index > 0; index--) | ||
| this.jobDone(); | ||
| this.pauseCount = 0; | ||
| } | ||
| public addJob(callback: queueCallback<returnType>, transferData: returnType): void { | ||
| this._stackJobs.push({ callback, data: transferData }); | ||
| } | ||
| /** | ||
| * name | ||
| */ | ||
| public runJobs(): void { | ||
| if (this._stackJobs.length <= this._queueCount) | ||
| this._queueCount = this._stackJobs.length; | ||
| this._stackJobs = this._stackJobs.reverse(); | ||
| this.queueActual = this._queueCount; | ||
| for (let index = 0; index < this._queueCount; index++) { | ||
| let runInstance = this._stackJobs.pop(); | ||
| runInstance?.callback(runInstance.data, index); | ||
| } | ||
| } | ||
| public jobDone(): void { | ||
| if (!this.isPause) { | ||
| if (this._stackJobs.length !== 0) { | ||
| let runInstance = this._stackJobs.pop(); | ||
| runInstance?.callback(runInstance.data, this._queueCount++); | ||
| } else if (--this.queueActual === 0) | ||
| this.doneCallback(); | ||
| } else if (this.queueActual == ++this.pauseCount) | ||
| this.pauseCallback(); | ||
| } | ||
| public isDone(callback: () => void): void { | ||
| this.doneCallback = callback; | ||
| } | ||
| private _queueCount: number; | ||
| public get queueCount(): number { | ||
| return this._queueCount; | ||
| } | ||
| public set queueCount(value: number) { | ||
| this._queueCount = value; | ||
| } | ||
| } | ||
| export { VanillaQueues, queueCallback, IVanillaQueues }; |
+26
| import { VanillaQueues } from "."; | ||
| let vanilaQue = new VanillaQueues<number>(5); | ||
| for (let index = 0; index < 100; index++) { | ||
| vanilaQue.addJob((data, counter) => { | ||
| console.log(counter,"****"); | ||
| setTimeout(() => { | ||
| console.log(data, "------> executed ---->", counter); | ||
| vanilaQue.jobDone(); | ||
| }, Math.floor(Math.random() * 3000) + 1000);//Math.floor(Math.random() * 2000) + | ||
| }, index); | ||
| } | ||
| vanilaQue.isDone(() => { | ||
| console.log("oeeeeee done..."); | ||
| }); | ||
| vanilaQue.runJobs(); | ||
| setTimeout(()=>vanilaQue.pause(()=>console.log("pause successfully...") | ||
| ),10000); | ||
| setTimeout(()=>vanilaQue.resume(),30000); | ||
@@ -0,3 +1,9 @@ | ||
| "use strict"; | ||
| var VanillaQueues = /** @class */ (function () { | ||
| function VanillaQueues(queueCountInit) { | ||
| this.doneCallback = function () { }; | ||
| this.pauseCallback = function () { }; | ||
| this.queueActual = 0; | ||
| this.isPause = false; | ||
| this.pauseCount = 0; | ||
| if (queueCountInit && parseInt(queueCountInit.toString()) >= 1) | ||
@@ -9,2 +15,21 @@ this._queueCount = queueCountInit; | ||
| } | ||
| VanillaQueues.prototype.stop = function () { | ||
| this._stackJobs = []; | ||
| this.queueActual = 0; | ||
| }; | ||
| VanillaQueues.prototype.breakCall = function (callback, everyNumberJobDone) { | ||
| if (!everyNumberJobDone) | ||
| throw new Error("Method not implemented."); | ||
| }; | ||
| VanillaQueues.prototype.pause = function (callback) { | ||
| if (callback) | ||
| this.pauseCallback = callback; | ||
| this.isPause = true; | ||
| }; | ||
| VanillaQueues.prototype.resume = function () { | ||
| this.isPause = false; | ||
| for (var index = this.pauseCount; index > 0; index--) | ||
| this.jobDone(); | ||
| this.pauseCount = 0; | ||
| }; | ||
| VanillaQueues.prototype.addJob = function (callback, transferData) { | ||
@@ -23,12 +48,16 @@ this._stackJobs.push({ callback: callback, data: transferData }); | ||
| var runInstance = this._stackJobs.pop(); | ||
| runInstance.callback(runInstance.data, index); | ||
| runInstance === null || runInstance === void 0 ? void 0 : runInstance.callback(runInstance.data, index); | ||
| } | ||
| }; | ||
| VanillaQueues.prototype.jobDone = function () { | ||
| if (this._stackJobs.length !== 0) { | ||
| var runInstance = this._stackJobs.pop(); | ||
| runInstance.callback(runInstance.data, this._queueCount++); | ||
| if (!this.isPause) { | ||
| if (this._stackJobs.length !== 0) { | ||
| var runInstance = this._stackJobs.pop(); | ||
| runInstance === null || runInstance === void 0 ? void 0 : runInstance.callback(runInstance.data, this._queueCount++); | ||
| } | ||
| else if (--this.queueActual === 0) | ||
| this.doneCallback(); | ||
| } | ||
| else if (--this.queueActual === 0) | ||
| this.doneCallback(); | ||
| else if (this.queueActual == ++this.pauseCount) | ||
| this.pauseCallback(); | ||
| }; | ||
@@ -45,3 +74,3 @@ VanillaQueues.prototype.isDone = function (callback) { | ||
| }, | ||
| enumerable: true, | ||
| enumerable: false, | ||
| configurable: true | ||
@@ -51,2 +80,3 @@ }); | ||
| }()); | ||
| // export { VanillaQueues, queueCallback, IVanillaQueues }; | ||
| // export { VanillaQueues, queueCallback, IVanillaQueues }; | ||
| //# sourceMappingURL=index.js.map |
+3
-2
| { | ||
| "name": "vanilla-queues-js", | ||
| "version": "1.0.7", | ||
| "version": "1.1.0", | ||
| "description": "create async jobs in queues/threads this can be handle in node, typescript, angular, react, vue, and all js based framework", | ||
| "main": "index.js", | ||
| "main": "dist/index.js", | ||
| "types": "dist", | ||
| "scripts": { | ||
@@ -7,0 +8,0 @@ "test": "echo \"Error: no test specified\" && exit 1" |
+72
-14
| { | ||
| "compileOnSave": true, | ||
| "compilerOptions": { | ||
| "compilerOptions": { | ||
| /* Visit https://aka.ms/tsconfig.json to read more about this file */ | ||
| "target": "es5", | ||
| "noImplicitAny": true, | ||
| "sourceMap": true, | ||
| "downlevelIteration": true, | ||
| "outDir":"" | ||
| }, | ||
| "exclude": [ | ||
| "node_modules", | ||
| "static" | ||
| ] | ||
| /* Basic Options */ | ||
| // "incremental": true, /* Enable incremental compilation */ | ||
| "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ | ||
| "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ | ||
| // "lib": [], /* Specify library files to be included in the compilation. */ | ||
| // "allowJs": true, /* Allow javascript files to be compiled. */ | ||
| // "checkJs": true, /* Report errors in .js files. */ | ||
| // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */ | ||
| "declaration": true, /* Generates corresponding '.d.ts' file. */ | ||
| "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ | ||
| "sourceMap": true, /* Generates corresponding '.map' file. */ | ||
| // "outFile": "./", /* Concatenate and emit output to single file. */ | ||
| "outDir": "dist", /* Redirect output structure to the directory. */ | ||
| // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ | ||
| // "composite": true, /* Enable project compilation */ | ||
| // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ | ||
| // "removeComments": true, /* Do not emit comments to output. */ | ||
| // "noEmit": true, /* Do not emit outputs. */ | ||
| // "importHelpers": true, /* Import emit helpers from 'tslib'. */ | ||
| "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ | ||
| // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ | ||
| /* Strict Type-Checking Options */ | ||
| "strict": true, /* Enable all strict type-checking options. */ | ||
| // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ | ||
| // "strictNullChecks": true, /* Enable strict null checks. */ | ||
| // "strictFunctionTypes": true, /* Enable strict checking of function types. */ | ||
| // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ | ||
| // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ | ||
| // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ | ||
| // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ | ||
| /* Additional Checks */ | ||
| // "noUnusedLocals": true, /* Report errors on unused locals. */ | ||
| // "noUnusedParameters": true, /* Report errors on unused parameters. */ | ||
| // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ | ||
| // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ | ||
| // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ | ||
| // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ | ||
| /* Module Resolution Options */ | ||
| // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ | ||
| // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ | ||
| // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ | ||
| // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ | ||
| // "typeRoots": [], /* List of folders to include type definitions from. */ | ||
| // "types": [], /* Type declaration files to be included in compilation. */ | ||
| // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ | ||
| "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ | ||
| // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ | ||
| // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ | ||
| /* Source Map Options */ | ||
| // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ | ||
| // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ | ||
| // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ | ||
| // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ | ||
| /* Experimental Options */ | ||
| // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ | ||
| // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ | ||
| /* Advanced Options */ | ||
| "skipLibCheck": true, /* Skip type checking of declaration files. */ | ||
| "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ | ||
| }, | ||
| "include": [ | ||
| "src" | ||
| ] | ||
| } |
-65
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var VanillaQueues = /** @class */ (function () { | ||
| function VanillaQueues(queueCountInit) { | ||
| if (queueCountInit && parseInt(queueCountInit.toString()) >= 1) | ||
| this._queueCount = queueCountInit; | ||
| else | ||
| this._queueCount = 5; | ||
| this._stackJobs = []; | ||
| } | ||
| VanillaQueues.prototype.addJob = function (callback, transferData) { | ||
| this._stackJobs.push({ callback: callback, data: transferData }); | ||
| }; | ||
| /** | ||
| * name | ||
| */ | ||
| VanillaQueues.prototype.runJobs = function () { | ||
| if (this._stackJobs.length <= this._queueCount) | ||
| this._queueCount = this._stackJobs.length; | ||
| this._stackJobs = this._stackJobs.reverse(); | ||
| this.queueActual = this._queueCount; | ||
| for (var index = 0; index < this._queueCount; index++) { | ||
| var runInstance = this._stackJobs.pop(); | ||
| runInstance.callback(runInstance.data, index); | ||
| } | ||
| }; | ||
| VanillaQueues.prototype.jobDone = function () { | ||
| if (this._stackJobs.length !== 0) { | ||
| var runInstance = this._stackJobs.pop(); | ||
| runInstance.callback(runInstance.data, this._queueCount++); | ||
| } | ||
| else if (--this.queueActual === 0) | ||
| this.doneCallback(); | ||
| }; | ||
| VanillaQueues.prototype.isDone = function (callback) { | ||
| this.doneCallback = callback; | ||
| }; | ||
| Object.defineProperty(VanillaQueues.prototype, "queueCount", { | ||
| get: function () { | ||
| return this._queueCount; | ||
| }, | ||
| set: function (value) { | ||
| this._queueCount = value; | ||
| }, | ||
| enumerable: true, | ||
| configurable: true | ||
| }); | ||
| return VanillaQueues; | ||
| }()); | ||
| exports.VanillaQueues = VanillaQueues; | ||
| // let vanilaQue = new VanillaQueues<number>(10); | ||
| // for (let index = 0; index < 5; index++) { | ||
| // vanilaQue.addJob((data, counter) => { | ||
| // console.log(counter,"****"); | ||
| // setTimeout(() => { | ||
| // console.log(data, "------> executed ---->", counter); | ||
| // vanilaQue.jobDone(); | ||
| // }, Math.floor(Math.random() * 3000) + 1000);//Math.floor(Math.random() * 2000) + | ||
| // }, index); | ||
| // } | ||
| // vanilaQue.isDone(() => { | ||
| // console.log("oeeeeee done..."); | ||
| // }); | ||
| // vanilaQue.runJobs(); | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names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EAAE,IAAI,CAAC,WAAW,KAAK,CAAC;YAC/B,IAAI,CAAC,YAAY,EAAE,CAAC;IAC5B,CAAC;IAEM,8BAAM,GAAb,UAAc,QAAoB;QAC9B,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC;IACjC,CAAC;IAUD,sBAAW,qCAAU;aAArB;YACI,OAAO,IAAI,CAAC,WAAW,CAAC;QAC5B,CAAC;aACD,UAAsB,KAAa;YAC/B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QAC7B,CAAC;;;OAHA;IAML,oBAAC;AAAD,CAAC,AA7DD,IA6DC;AAEQ,sCAAa;AAEtB,iDAAiD;AACjD,4CAA4C;AAC5C,4CAA4C;AAC5C,uCAAuC;AACvC,6BAA6B;AAC7B,oEAAoE;AACpE,mCAAmC;AACnC,2FAA2F;AAC3F,iBAAiB;AACjB,IAAI;AAEJ,2BAA2B;AAC3B,sCAAsC;AAEtC,MAAM;AAEN,uBAAuB"} |
-114
| /** | ||
| * @param data get data when pass before execution r | ||
| * @param counter job count execution by queue machine runJobs | ||
| */ | ||
| interface queueCallback<returnType> { | ||
| (data: returnType, counter: number): void; | ||
| } | ||
| interface IVanillaQueues<returnType> { | ||
| /** | ||
| * total count index start from 0 | ||
| */ | ||
| queueCount: number; | ||
| /** | ||
| * grobal array to mark as complete all jobs | ||
| * @param callback an evert is on succes | ||
| */ | ||
| isDone(callback: () => void): void; | ||
| /** | ||
| * | ||
| * @param callback as call back basses of transfer | ||
| * @param transferData callback data ewcive | ||
| */ | ||
| addJob(callback: queueCallback<returnType>, transferData: returnType): void; | ||
| runJobs(): void; | ||
| jobDone(): void; | ||
| } | ||
| class VanillaQueues<returnType> implements IVanillaQueues<returnType> { | ||
| private doneCallback: () => void; | ||
| private queueActual: number; | ||
| constructor(queueCountInit?: number) { | ||
| if (queueCountInit && parseInt(queueCountInit.toString()) >= 1) | ||
| this._queueCount = queueCountInit; | ||
| else | ||
| this._queueCount = 5; | ||
| this._stackJobs = []; | ||
| } | ||
| public addJob(callback: queueCallback<returnType>, transferData: returnType): void { | ||
| this._stackJobs.push({ callback: callback, data: transferData }); | ||
| } | ||
| /** | ||
| * name | ||
| */ | ||
| public runJobs(): void { | ||
| if (this._stackJobs.length <= this._queueCount) | ||
| this._queueCount = this._stackJobs.length; | ||
| this._stackJobs = this._stackJobs.reverse(); | ||
| this.queueActual = this._queueCount; | ||
| for (let index = 0; index < this._queueCount; index++) { | ||
| let runInstance = this._stackJobs.pop(); | ||
| runInstance.callback(runInstance.data, index); | ||
| } | ||
| } | ||
| public jobDone(): void { | ||
| if (this._stackJobs.length !== 0) { | ||
| let runInstance = this._stackJobs.pop(); | ||
| runInstance.callback(runInstance.data, this._queueCount++); | ||
| } else if (--this.queueActual === 0) | ||
| this.doneCallback(); | ||
| } | ||
| public isDone(callback: () => void): void { | ||
| this.doneCallback = callback; | ||
| } | ||
| private _stackJobs: { | ||
| callback: queueCallback<returnType>; | ||
| data: returnType; | ||
| }[]; | ||
| private _queueCount: number; | ||
| public get queueCount(): number { | ||
| return this._queueCount; | ||
| } | ||
| public set queueCount(value: number) { | ||
| this._queueCount = value; | ||
| } | ||
| } | ||
| export { VanillaQueues, queueCallback, IVanillaQueues }; | ||
| // let vanilaQue = new VanillaQueues<number>(10); | ||
| // for (let index = 0; index < 5; index++) { | ||
| // vanilaQue.addJob((data, counter) => { | ||
| // console.log(counter,"****"); | ||
| // setTimeout(() => { | ||
| // console.log(data, "------> executed ---->", counter); | ||
| // vanilaQue.jobDone(); | ||
| // }, Math.floor(Math.random() * 3000) + 1000);//Math.floor(Math.random() * 2000) + | ||
| // }, index); | ||
| // } | ||
| // vanilaQue.isDone(() => { | ||
| // console.log("oeeeeee done..."); | ||
| // }); | ||
| // vanilaQue.runJobs(); | ||
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
65371
29.95%17
70%429
100.47%1
Infinity%