Skip to content

Commit 1fb3fbf

Browse files
committed
feat: add TimeQueue#isFull()
closes #13
1 parent 61b23cc commit 1fb3fbf

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ How many tasks are currently in the queue.
7474
How many tasks have finished in total.
7575

7676
### TimeQueue#push(data..., [callback])
77-
Pushes a new task to the queue. Any number of arguments can be given. An optional callback can also be given as the last parameter. The callback will be called when the task is finished or if there was any error.
77+
Pushes a new task to the queue. Any number of arguments can be given. An optional callback can also be given as the last parameter. The callback will be called when the task is finished or if there was any error running the worker.
78+
79+
If the queue is full, pushed tasks will be ignored.
80+
81+
### TimeQueue#isFull()
82+
Returns true if queue is full.
7883

7984
### TimeQueue#die()
8085
Empties queue and clears the timeouts TimeQueue sets to keep track of running tasks. Currently running tasks will still complete.

lib/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports = class TimeQueue extends EventEmitter {
4444
* @param {Function(!Error, ...)} callback
4545
*/
4646
push(...args) {
47-
if (this.maxQueued === this.queued) {
47+
if (this.isFull()) {
4848
return;
4949
}
5050

@@ -62,6 +62,16 @@ module.exports = class TimeQueue extends EventEmitter {
6262
}
6363

6464

65+
/**
66+
* Returns true if queue is full.
67+
*
68+
* @return {boolean}
69+
*/
70+
isFull() {
71+
return this.maxQueued === this.queued;
72+
}
73+
74+
6575
/**
6676
* Starts a task
6777
*

0 commit comments

Comments
 (0)