Skip to content

Instantly share code, notes, and snippets.

@mamuesp
Created March 13, 2019 12:10
Show Gist options
  • Save mamuesp/e2d026b59b04d5174ec11598a5c526a3 to your computer and use it in GitHub Desktop.
Save mamuesp/e2d026b59b04d5174ec11598a5c526a3 to your computer and use it in GitHub Desktop.
Queue "prototyp" fpr MJS
load("api_config.js");
let protQueue = {
_queue: [],
isEmpty: function() {
return (this._queue.length === 0);
},
add: function(obj) {
this._queue.push(obj);
},
count: function() {
return this._queue.length;
},
first: function(remove) {
if (this.isEmpty()) {
return {};
} else {
let elem = this._queue[0];
if (remove) {
this._queue.splice(0, 1);
}
return elem;
}
},
last: function(remove) {
if (this.isEmpty()) {
return {};
} else {
let elem = this._queue[this._queue.length - 1];
if (remove) {
this._queue.splice(this._queue.length - 1, 1);
}
return elem;
}
},
print: function() {
for (let i = 0; i < this._queue.length; i++) {
let msg = 'Queue entry - JSON: ' + JSON.stringify(this._queue[i]);
Log.debug(msg);
}
},
get: function() {
return this._queue;
},
set: function(value) {
this._queue = value;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment