Skip to content

Commit

Permalink
Add space events
Browse files Browse the repository at this point in the history
  • Loading branch information
erayd committed Jan 2, 2020
1 parent c660a4b commit 8742f7d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,6 @@ The queue is full.

#### empty
The queue is empty.

#### space
The queue has space available to store more items.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spique",
"version": "2.1.0",
"version": "2.2.0",
"description": "A spiral deque - high performance and dynamic queue size",
"main": "spique.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions ringbuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ module.exports = class Ringbuffer extends events.EventEmitter {
buffer[pos] = undefined;
if (this.isEmpty())
this.emit("empty", this);
if (items < size)
this.emit("space", this);
return value;
};

Expand All @@ -87,6 +89,8 @@ module.exports = class Ringbuffer extends events.EventEmitter {
items--;
if (this.isEmpty())
this.emit("empty", this);
if (items < size)
this.emit("space", this);
return value;
};

Expand Down
4 changes: 4 additions & 0 deletions spique.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ module.exports = class Spique extends events.EventEmitter {
items--;
if (items === 0)
this.emit("empty", this);
if (items < maxItems)
this.emit("space", this);
return value;
};

Expand All @@ -137,6 +139,8 @@ module.exports = class Spique extends events.EventEmitter {
items--;
if (items === 0)
this.emit("empty", this);
if (items < maxItems)
this.emit("space", this);
return value;
};

Expand Down

0 comments on commit 8742f7d

Please sign in to comment.