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