3 Copyright 2012 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
7 YUI.add('io-queue', function(Y) {
10 Extends IO to implement Queue for synchronous
11 transaction processing.
16 var io = Y.io._map['io:0'] || new Y.IO();
18 Y.mix(Y.IO.prototype, {
20 * Array of transactions queued for processing
31 * Property to determine whether the queue is set to
32 * 1 (active) or 0 (inactive). When inactive, transactions
33 * will be stored in the queue until the queue is set to active.
43 * Method Process the first transaction from the
44 * queue in FIFO order.
56 io.send(o.uri, o.cfg, o.id);
60 * Method for queueing a transaction before the request is sent to the
61 * resource, to ensure sequential processing.
67 queue: function(uri, c) {
69 o = { uri: uri, cfg:c, id: this._id++ };
72 Y.on('io:complete', function(id, o) { io._qNext(id); }, io);
77 if (io._qState === 1) {
84 _qNext: function(id) {
87 if (io._qActiveId === id && io._q.size() > 0) {
93 * Method for promoting a transaction to the top of the queue.
98 qPromote: function(o) {
103 * Method for removing a specific, pending transaction from
110 qRemove: function(o) {
118 if (io._q.size() > 0) {
124 * Method for setting queue processing to inactive.
125 * Transaction requests to YUI.io.queue() will be stored in the queue, but
126 * not processed until the queue is reset to "active".
137 * Method to query the current size of the queue.
145 return this._q.size();
150 function _queue(u, c) {
151 return io.queue.apply(io, [u, c]);
154 _queue.start = function () { io.qStart(); };
155 _queue.stop = function () { io.qStop(); };
156 _queue.promote = function (o) { io.qPromote(o); };
157 _queue.remove = function (o) { io.qRemove(o); };
158 _queue.size = function () { io.qSize(); };
162 }, '3.5.0' ,{requires:['io-base','queue-promote']});