queue-base.js revision 2c5ce90c334a2d0f18474e85c93b424b6ec9daaa
6643N/A/**
6643N/A * The YUI module contains the components required for building the YUI seed file.
6643N/A * This includes the script loading mechanism, a simple queue, and the core utilities for the library.
6643N/A * @module yui
6643N/A * @submodule yui-base
6643N/A */
6643N/A
6643N/A/**
6643N/A * A simple FIFO queue. Items are added to the Queue with add(1..n items) and
6643N/A * removed using next().
6643N/A *
6643N/A * @module queue
6643N/A * @submodule queue-base
6643N/A * @class Queue
6643N/A * @param item* {MIXED} 0..n items to seed the queue
6643N/A */
6643N/Afunction Queue() {
6643N/A this._init();
6643N/A this.add.apply(this, arguments);
6643N/A}
6643N/A
6643N/AQueue.prototype = {
6643N/A /**
6643N/A * Initialize the queue
6643N/A *
6643N/A * @method _init
6643N/A * @protected
6643N/A */
6643N/A _init : function () {
6643N/A /**
6643N/A * The collection of enqueued items
6643N/A *
6643N/A * @property _q
6643N/A * @type {Array}
6643N/A * @protected
6643N/A */
6643N/A this._q = [];
6643N/A },
6643N/A
6643N/A /**
6643N/A * Get the next item in the queue.
6643N/A *
6643N/A * @method next
6643N/A * @return {MIXED} the next item in the queue
6643N/A */
6643N/A next : function () {
6643N/A return this._q.shift();
6643N/A },
6643N/A
6643N/A /**
6643N/A * Add 0..n items to the end of the queue
6643N/A *
6643N/A * @method add
6643N/A * @param item* {MIXED} 0..n items
6643N/A */
6643N/A add : function () {
6643N/A Y.Array.each(Y.Array(arguments,0,true),function (fn) {
6643N/A this._q.push(fn);
6643N/A },this);
6643N/A
6643N/A return this;
6643N/A },
6643N/A
6643N/A /**
6643N/A * Returns the current number of queued items
6643N/A *
6643N/A * @method size
6643N/A * @return {Number}
6643N/A */
6643N/A size : function () {
6643N/A return this._q.length;
6643N/A }
6643N/A};
6643N/A
6643N/AY.Queue = Queue;
6643N/A