2
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.net/yui/license.txt
7
YUI.add('io-queue', function(Y) {
10
* Extends the IO base class to include basic queue interfaces for transaction
17
* @description Array of transactions queued for processing
27
* @description Property to determine whether the queue is set to
28
* 1 (active) or 0 (inactive). When inactive, transactions
29
* will be stored in the queue until the queue is set to active.
39
* @description Queue property to set a maximum queue storage size. When
40
* this property is set, the queue will not store any more transactions
41
* until the queue size os reduced below this threshold. There is no
42
* maximum queue size until it is explicitly set.
52
* @description Method for requesting a transaction, and queueing the
53
* request before it is sent to the resource.
60
function _queue(uri, c) {
62
if (_qMaxSize === false || _q.length < _qMaxSize) {
64
_q.push({ uri: uri, id: id, cfg:c });
78
* @description Method for promoting a transaction to the top of the queue.
85
function _unshift(id) {
88
for (var i = 0; i < _q.length; i++) {
89
if (_q[i].id === id) {
91
var p = _q.unshift(r[0]);
98
* @description Method for removing a transaction from the top of the
99
* queue, and sending the transaction to _io().
108
Y.io(c.uri, c.cfg, c.id);
112
* @description Method to query the current size of the queue, or to
113
* set a maximum queue size.
131
* @description Method for setting the queue to active. If there are
132
* transactions pending in the queue, they will be processed from the
133
* queue in FIFO order.
141
var len = (_q.length > _qMaxSize > 0) ? _qMaxSize : _q.length;
144
for (var i=0; i < len; i++) {
155
* @description Method for setting queue processing to inactive.
156
* Transaction requests to YUI.io.queue() will be stored in the queue, but
157
* not processed until the queue is reset to "active".
169
* @description Method for removing a specific, pending transaction from
177
function _purge(id) {
178
if (Y.Lang.isNumber(id)) {
179
for (var i = 0; i < _q.length; i++) {
180
if (_q[i].id === id) {
189
* @description Method to query the current size of the queue, or to
190
* set a maximum queue size. This is the interface for _size().
195
* @param {number} i - Specified maximum size of queue.
201
* @description Method for setting the queue to "active". If there are
202
* transactions pending in the queue, they will be processed from the
203
* queue in FIFO order. This is the interface for _start().
210
_queue.start = _start;
213
* @description Method for setting queue processing to inactive.
214
* Transaction requests to YUI.io.queue() will be stored in the queue, but
215
* not processed until the queue is set to "active". This is the
216
* interface for _stop().
226
* @description Method for promoting a transaction to the top of the queue.
227
* This is the interface for _unshift().
232
* @param {number} i - ID of queued transaction.
235
_queue.promote = _unshift;
238
* @description Method for removing a specific, pending transaction from
239
* the queue. This is the interface for _purge().
244
* @param {number} i - ID of queued transaction.
247
_queue.purge = _purge;
255
}, '3.0.0pr2' ,{requires:['io-base']});