diffusion
Version:
Diffusion JavaScript client
55 lines (54 loc) • 1.42 kB
JavaScript
;
/**
* @module Util.Queue
*
* @brief A simple queue implementation
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Queue = void 0;
/**
* This class represent a message queue where messages can be added, removed and
* can query the state of the queue i.e. if the queue is currently empty or not.
*/
var Queue = /** @class */ (function () {
function Queue() {
/**
* The array storing the elements in the queue
*/
this.messages = [];
}
/**
* Get the length of the quque
*
* @returns number of queued items
*/
Queue.prototype.length = function () {
return this.messages.length;
};
/**
* Add a message to the messages queue.
*
* @param message the message to be added
*/
Queue.prototype.add = function (message) {
this.messages.push(message);
};
/**
* Removes then returns all messages from the queue as an array.
*
* @returns an array of removed messages
*/
Queue.prototype.drain = function () {
return this.messages.splice(0, this.messages.length);
};
/**
* Check if there are no more items in the queue
*
* @returns `true` if the queue is empty
*/
Queue.prototype.isEmpty = function () {
return this.messages.length === 0;
};
return Queue;
}());
exports.Queue = Queue;