Skip to content

Commit

Permalink
feat: add TimeQueue#isFull()
Browse files Browse the repository at this point in the history
closes #13
  • Loading branch information
fent committed Feb 24, 2019
1 parent 61b23cc commit 1fb3fbf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ How many tasks are currently in the queue.
How many tasks have finished in total.

### TimeQueue#push(data..., [callback])
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.
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.

If the queue is full, pushed tasks will be ignored.

### TimeQueue#isFull()
Returns true if queue is full.

### TimeQueue#die()
Empties queue and clears the timeouts TimeQueue sets to keep track of running tasks. Currently running tasks will still complete.
Expand Down
12 changes: 11 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = class TimeQueue extends EventEmitter {
* @param {Function(!Error, ...)} callback
*/
push(...args) {
if (this.maxQueued === this.queued) {
if (this.isFull()) {
return;
}

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


/**
* Returns true if queue is full.
*
* @return {boolean}
*/
isFull() {
return this.maxQueued === this.queued;
}


/**
* Starts a task
*
Expand Down

0 comments on commit 1fb3fbf

Please sign in to comment.