Skip to content

Commit

Permalink
Clean up close()
Browse files Browse the repository at this point in the history
  • Loading branch information
jhead committed Mar 23, 2016
1 parent b2b60ed commit b5019d6
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let MessageQueue = function(key, perms, options) {
this.flags = formatFlags(perms);
this.options = options || { };

this.closed = false;
this.receiveBuffer = [];

this.on('newListener', (event) => {
Expand Down Expand Up @@ -134,10 +135,23 @@ MessageQueue.prototype.pop = function(options, callback) {
this._receive(options, callback);
};

MessageQueue.prototype.close = function() {
if (this.closed) throw new Error('Queue already closed');
MessageQueue.prototype.close = function(callback) {
callback = callback || Function.prototype;

return (this.closed = msg.close(this.id));
if (this.closed) {
callback(null, true);
return true;
}

try {
this.closed = msg.close(this.id)
} catch (err) {
callback(err, false);
return false;
}

callback(null, true);
return true;
};

function formatFlags(perms) {
Expand All @@ -157,7 +171,6 @@ function formatFlags(perms) {
// Static members and constants
const IPC_CREATE = MessageQueue.IPC_CREATE = 512;
const MSGMAX = MessageQueue.MSGMAX = 4052;
// MessageQueue.IPC_RMID =
MessageQueue.formatFlags = formatFlags;

// Export native bindings
Expand Down

0 comments on commit b5019d6

Please sign in to comment.