UNPKG

@barchart/common-js

Version:
68 lines (67 loc) 1.71 kB
/** * A queue collection that supports FIFO operations. * * @public */ export default class Queue { /** * Adds an item to the end of the queue. * * @public * @param {*} item - The item to add. * @returns {*} The item added to the queue. */ public enqueue(item: any): any; /** * Removes the next item from the queue and returns it. Throws if the queue is empty. * * @public * @returns {*} The item removed from the queue. * @throws {Error} If the queue is empty. */ public dequeue(): any; /** * Returns the next item in the queue without removing it. * * @public * @returns {*} The next item in the queue. * @throws {Error} If the queue is empty. */ public peek(): any; /** * Indicates whether the queue is empty. * * @public * @returns {boolean} True if the queue is empty; otherwise, false. */ public empty(): boolean; /** * Runs an action on each item in the queue. * * @public * @param {Function} action - The action to run. */ public scan(action: Function): void; /** * Returns a copy of the queue's items without affecting its internal state. * * @public * @returns {Array<*>} A copy of the queue's items. */ public toArray(): Array<any>; /** * Returns the queue's internal array for use by derived classes. * * @protected * @returns {Array<*>} The internal array. */ protected _getArray(): Array<any>; /** * Returns a string representation. * * @public * @returns {string} */ public toString(): string; #private; }