2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
8 YUI.add('io-queue', function(Y) {
11 * Extends the IO base class to implement Queue for synchronous
12 * transaction processing.
18 * @description Array of transactions queued for processing
25 var _q = new Y.Queue(),
28 * @description Reference to "io:complete" event handler.
39 * @description Property to determine whether the queue is set to
40 * 1 (active) or 0 (inactive). When inactive, transactions
41 * will be stored in the queue until the queue is set to active.
51 * @description Method for requesting a transaction, and queueing the
52 * request before it is sent to the resource.
59 function _queue(uri, c) {
60 var o = { uri: uri, id: Y.io._id(), cfg:c };
71 * @description Method Process the first transaction from the
72 * queue in FIFO order.
84 Y.io(o.uri, o.cfg, o.id);
88 * @description Method for promoting a transaction to the top of the queue.
95 function _unshift(o) {
101 if (_activeId === id && _q.size() > 0) {
107 * @description Method for removing a specific, pending transaction from
115 function _remove(o) {
128 * @description Method for setting queue processing to inactive.
129 * Transaction requests to YUI.io.queue() will be stored in the queue, but
130 * not processed until the queue is reset to "active".
142 * @description Method to query the current size of the queue.
153 _e = Y.on('io:complete', function(id) { _next(id); }, Y.io);
156 * @description Method to query the current size of the queue, or to
157 * set a maximum queue size. This is the interface for _size().
162 * @param {number} i - Specified maximum size of queue.
168 * @description Method for setting the queue to active. If there are
169 * transactions pending in the queue, they will be processed from the
170 * queue in FIFO order. This is the interface for _start().
177 _queue.start = _start;
180 * @description Method for setting queue processing to inactive.
181 * Transaction requests to YUI.io.queue() will be stored in the queue, but
182 * not processed until the queue is restarted. This is the
183 * interface for _stop().
193 * @description Method for promoting a transaction to the top of the queue.
194 * This is the interface for _unshift().
199 * @param {Object} o - Reference to queued transaction.
202 _queue.promote = _unshift;
205 * @description Method for removing a specific, pending transaction from
206 * the queue. This is the interface for _remove().
211 * @param {Object} o - Reference to queued transaction.
214 _queue.remove = _remove;
222 }, '3.0.0' ,{requires:['io-base','queue-promote']});