vanilla-queues-js
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -28,3 +28,3 @@ /** | ||
addJob(callback: queueCallback<returnType>, transferData: returnType): void; | ||
breakCall(callback: () => void, everyNumberJobDone: number): void; | ||
achiveLapsNotification(callback: () => void, countJobsInLap: number): void; | ||
pause(): void; | ||
@@ -41,6 +41,9 @@ resume(): void; | ||
private isPause; | ||
private achivedLaps; | ||
private laps; | ||
private achiveLapsCallback; | ||
private _stackJobs; | ||
constructor(queueCountInit?: number); | ||
achiveLapsNotification(callback: () => void, countJobsInLap: number): void; | ||
stop(): void; | ||
breakCall(callback: () => void, everyNumberJobDone: number): void; | ||
pauseCount: number; | ||
@@ -47,0 +50,0 @@ pause(callback?: () => void): void; |
@@ -6,6 +6,6 @@ "use strict"; | ||
function VanillaQueues(queueCountInit) { | ||
this.doneCallback = function () { }; | ||
this.pauseCallback = function () { }; | ||
this.queueActual = 0; | ||
this.isPause = false; | ||
this.achivedLaps = 0; | ||
this.laps = 0; | ||
this.pauseCount = 0; | ||
@@ -18,2 +18,7 @@ if (queueCountInit && parseInt(queueCountInit.toString()) >= 1) | ||
} | ||
VanillaQueues.prototype.achiveLapsNotification = function (callback, countJobsInLap) { | ||
if (callback) | ||
this.achiveLapsCallback = callback; | ||
this.laps = countJobsInLap; | ||
}; | ||
VanillaQueues.prototype.stop = function () { | ||
@@ -23,6 +28,2 @@ this._stackJobs = []; | ||
}; | ||
VanillaQueues.prototype.breakCall = function (callback, everyNumberJobDone) { | ||
if (!everyNumberJobDone) | ||
throw new Error("Method not implemented."); | ||
}; | ||
VanillaQueues.prototype.pause = function (callback) { | ||
@@ -60,2 +61,4 @@ if (callback) | ||
runInstance === null || runInstance === void 0 ? void 0 : runInstance.callback(runInstance.data, this._queueCount++); | ||
if (this.laps && (this._queueCount % this.laps) == 0 && this.achiveLapsCallback) | ||
this.achiveLapsCallback(); | ||
} | ||
@@ -62,0 +65,0 @@ else if (--this.queueActual === 0) |
@@ -17,2 +17,5 @@ "use strict"; | ||
}); | ||
vanilaQue.achiveLapsNotification(function () { | ||
console.log("lap achived..."); | ||
}, 10); | ||
vanilaQue.runJobs(); | ||
@@ -19,0 +22,0 @@ setTimeout(function () { return vanilaQue.pause(function () { return console.log("pause successfully..."); }); }, 10000); |
{ | ||
"name": "vanilla-queues-js", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "create async jobs in queues/threads this can be handle in node, typescript, angular, react, vue, and all js based framework", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -81,1 +81,19 @@ # vanilla-queues-js | ||
- `RESUME` - Resume pause task, note: only pause tast are only to be resume. ``` vanilaQue.resume() ``` | ||
- `Laps Notification` - Notify by callback user define number of jobs complete. ``` vanilaQue.achiveLapsNotification(CALLBACK,10) ``` "10" means notify you when every 10 jobs are done. | ||
### Pause | ||
``` | ||
vanilaQue.pause(()=>console.log("pause successfully..."); | ||
``` | ||
### Laps Notification | ||
Notify by callback user define number of jobs complete. ``` vanilaQue.achiveLapsNotification(CALLBACK,10) ``` "10" means notify you when every 10 jobs are done. | ||
``` | ||
vanilaQue.achiveLapsNotification(()=>{ | ||
console.log("lap achived..."); | ||
},10) | ||
``` |
@@ -32,6 +32,6 @@ | ||
addJob(callback: queueCallback<returnType>, transferData: returnType): void; | ||
breakCall(callback: () => void, everyNumberJobDone: number): void; | ||
achiveLapsNotification(callback: () => void, countJobsInLap: number): void; | ||
pause(): void; | ||
resume(): void; | ||
stop():void; | ||
stop(): void; | ||
runJobs(): void; | ||
@@ -45,6 +45,9 @@ jobDone(): void; | ||
private doneCallback: () => void = function () { }; | ||
private pauseCallback: () => void = function () { }; | ||
private declare doneCallback: () => void; | ||
private declare pauseCallback: () => void; | ||
private queueActual: number = 0; | ||
private isPause: boolean = false; | ||
private achivedLaps: number = 0; | ||
private laps: number = 0; | ||
private declare achiveLapsCallback: () => void; | ||
// private | ||
@@ -64,10 +67,12 @@ private _stackJobs: { | ||
} | ||
stop(): void { | ||
this._stackJobs=[]; | ||
this.queueActual=0; | ||
achiveLapsNotification(callback: () => void, countJobsInLap: number): void { | ||
if (callback) | ||
this.achiveLapsCallback = callback; | ||
this.laps = countJobsInLap; | ||
} | ||
breakCall(callback: () => void, everyNumberJobDone: number): void { | ||
if (!everyNumberJobDone) | ||
throw new Error("Method not implemented."); | ||
stop(): void { | ||
this._stackJobs = []; | ||
this.queueActual = 0; | ||
} | ||
@@ -113,2 +118,5 @@ | ||
runInstance?.callback(runInstance.data, this._queueCount++); | ||
if (this.laps && (this._queueCount % this.laps) == 0 && this.achiveLapsCallback) | ||
this.achiveLapsCallback(); | ||
} else if (--this.queueActual === 0) | ||
@@ -115,0 +123,0 @@ this.doneCallback(); |
@@ -19,2 +19,6 @@ import { VanillaQueues } from "."; | ||
vanilaQue.achiveLapsNotification(()=>{ | ||
console.log("lap achived..."); | ||
},10) | ||
vanilaQue.runJobs(); | ||
@@ -21,0 +25,0 @@ |
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
67880
18
466
99