src/cm/media/js/lib/yui/yui3-3.15.0/build/io-queue/io-queue-debug.js
changeset 602 e16a97fb364a
equal deleted inserted replaced
601:d334a616c023 602:e16a97fb364a
       
     1 YUI.add('io-queue', function (Y, NAME) {
       
     2 
       
     3 /**
       
     4 Extends IO to implement Queue for synchronous
       
     5 transaction processing.
       
     6 @module io
       
     7 @submodule io-queue
       
     8 @for IO
       
     9 **/
       
    10 var io = Y.io._map['io:0'] || new Y.IO();
       
    11 
       
    12 Y.mix(Y.IO.prototype, {
       
    13    /**
       
    14     * Array of transactions queued for processing
       
    15     *
       
    16     * @property _q
       
    17     * @private
       
    18     * @static
       
    19     * @type {Object}
       
    20     */
       
    21     _q: new Y.Queue(),
       
    22     _qActiveId: null,
       
    23     _qInit: false,
       
    24 
       
    25    /**
       
    26     * Property to determine whether the queue is set to
       
    27     * 1 (active) or 0 (inactive).  When inactive, transactions
       
    28     * will be stored in the queue until the queue is set to active.
       
    29     *
       
    30     * @property _qState
       
    31     * @private
       
    32     * @static
       
    33     * @type {Number}
       
    34     */
       
    35     _qState: 1,
       
    36 
       
    37    /**
       
    38     * Method Process the first transaction from the
       
    39     * queue in FIFO order.
       
    40     *
       
    41     * @method _qShift
       
    42     * @private
       
    43     * @static
       
    44     */
       
    45     _qShift: function() {
       
    46         var io = this,
       
    47             o = io._q.next();
       
    48 
       
    49         io._qActiveId = o.id;
       
    50         io._qState = 0;
       
    51         io.send(o.uri, o.cfg, o.id);
       
    52     },
       
    53 
       
    54    /**
       
    55     * Method for queueing a transaction before the request is sent to the
       
    56     * resource, to ensure sequential processing.
       
    57     *
       
    58     * @method queue
       
    59     * @static
       
    60     * @return {Object}
       
    61     */
       
    62     queue: function(uri, c) {
       
    63         var io = this,
       
    64             o = { uri: uri, cfg:c, id: this._id++ };
       
    65 
       
    66         if(!io._qInit) {
       
    67             Y.on('io:complete', function(id, o) { io._qNext(id); }, io);
       
    68             io._qInit = true;
       
    69         }
       
    70 
       
    71         io._q.add(o);
       
    72         if (io._qState === 1) {
       
    73             io._qShift();
       
    74         }
       
    75 
       
    76         Y.log('Object queued.  Transaction id is' + o.id, 'info', 'io');
       
    77         return o;
       
    78     },
       
    79 
       
    80     _qNext: function(id) {
       
    81         var io = this;
       
    82         io._qState = 1;
       
    83         if (io._qActiveId === id && io._q.size() > 0) {
       
    84             io._qShift();
       
    85         }
       
    86     },
       
    87 
       
    88    /**
       
    89     * Method for promoting a transaction to the top of the queue.
       
    90     *
       
    91     * @method promote
       
    92     * @static
       
    93     */
       
    94     qPromote: function(o) {
       
    95         this._q.promote(o);
       
    96     },
       
    97 
       
    98    /**
       
    99     * Method for removing a specific, pending transaction from
       
   100     * the queue.
       
   101     *
       
   102     * @method remove
       
   103     * @private
       
   104     * @static
       
   105     */
       
   106     qRemove: function(o) {
       
   107         this._q.remove(o);
       
   108     },
       
   109 
       
   110    /**
       
   111     * Method for cancel all pending transaction from
       
   112     * the queue.
       
   113     *
       
   114     * @method empty
       
   115     * @static
       
   116     * @since 3.7.3
       
   117     */
       
   118     qEmpty: function() {
       
   119         this._q = new Y.Queue();
       
   120     },
       
   121 
       
   122     qStart: function() {
       
   123         var io = this;
       
   124         io._qState = 1;
       
   125 
       
   126         if (io._q.size() > 0) {
       
   127             io._qShift();
       
   128         }
       
   129         Y.log('Queue started.', 'info', 'io');
       
   130     },
       
   131 
       
   132    /**
       
   133     * Method for setting queue processing to inactive.
       
   134     * Transaction requests to YUI.io.queue() will be stored in the queue, but
       
   135     * not processed until the queue is reset to "active".
       
   136     *
       
   137     * @method _stop
       
   138     * @private
       
   139     * @static
       
   140     */
       
   141     qStop: function() {
       
   142         this._qState = 0;
       
   143         Y.log('Queue stopped.', 'info', 'io');
       
   144     },
       
   145 
       
   146    /**
       
   147     * Method to query the current size of the queue.
       
   148     *
       
   149     * @method _size
       
   150     * @private
       
   151     * @static
       
   152     * @return {Number}
       
   153     */
       
   154     qSize: function() {
       
   155         return this._q.size();
       
   156     }
       
   157 
       
   158 }, true);
       
   159 
       
   160 function _queue(u, c) {
       
   161     return io.queue.apply(io, [u, c]);
       
   162 }
       
   163 
       
   164 _queue.start = function () { io.qStart(); };
       
   165 _queue.stop = function () { io.qStop(); };
       
   166 _queue.promote = function (o) { io.qPromote(o); };
       
   167 _queue.remove = function (o) { io.qRemove(o); };
       
   168 _queue.size = function () { io.qSize(); };
       
   169 _queue.empty = function () { io.qEmpty(); };
       
   170 Y.io.queue = _queue;
       
   171 
       
   172 
       
   173 }, '@VERSION@', {"requires": ["io-base", "queue-promote"]});