2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
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(),
29 * @description Property to determine whether the queue is set to
30 * 1 (active) or 0 (inactive). When inactive, transactions
31 * will be stored in the queue until the queue is set to active.
41 * @description Method Process the first transaction from the
42 * queue in FIFO order.
54 Y.io(o.uri, o.cfg, o.id);
58 * @description Method for promoting a transaction to the top of the queue.
65 function _unshift(o) {
70 * @description Method for requesting a transaction, and queueing the
71 * request before it is sent to the resource.
78 function _queue(uri, c) {
79 var o = { uri: uri, id: Y.io._id(), cfg:c };
91 if (_activeId === id && _q.size() > 0) {
97 * @description Method for removing a specific, pending transaction from
105 function _remove(o) {
118 * @description Method for setting queue processing to inactive.
119 * Transaction requests to YUI.io.queue() will be stored in the queue, but
120 * not processed until the queue is reset to "active".
132 * @description Method to query the current size of the queue.
144 * @description Method to query the current size of the queue, or to
145 * set a maximum queue size. This is the interface for _size().
150 * @param {number} i - Specified maximum size of queue.
156 * @description Method for setting the queue to active. If there are
157 * transactions pending in the queue, they will be processed from the
158 * queue in FIFO order. This is the interface for _start().
165 _queue.start = _start;
168 * @description Method for setting queue processing to inactive.
169 * Transaction requests to YUI.io.queue() will be stored in the queue, but
170 * not processed until the queue is restarted. This is the
171 * interface for _stop().
181 * @description Method for promoting a transaction to the top of the queue.
182 * This is the interface for _unshift().
187 * @param {Object} o - Reference to queued transaction.
190 _queue.promote = _unshift;
193 * @description Method for removing a specific, pending transaction from
194 * the queue. This is the interface for _remove().
199 * @param {Object} o - Reference to queued transaction.
202 _queue.remove = _remove;
204 Y.on('io:complete', function(id) { _next(id); }, Y.io);
212 }, '3.3.0' ,{requires:['io-base','queue-promote']});