Config
Table of Contents

Class

O.IOQueue

Extends
O.Object

Manage concurrent HTTP requests.

"use strict";


( function ( NS ) {


var QUEUE = 1,
 IGNORE = 2,
 ABORT = 3;

var IOQueue = NS.Class({

 Extends: NS.Object,

Private Property

O.IOQueue#_queue

  • Array
  • private

Queue of request objects waiting for current transactions to finish.

Property

O.IOQueue#_recent

  • (O.HttpRequest|null)

A reference to the most recent request.

Property

O.IOQueue#activeConnections

  • Number

The number of active connections

Property

O.IOQueue#maxConnections

  • Number

The maximum number of concurrent connections to make with this IOQueue object. Note, this is a per-instance value; each IOQueue instance may make up to maxConnections to the server as defined on that object.

maxConnections: 1,

Constructor

O.IOQueue( mixin )

Parameters

mixinObject An object containing new defaults for any of the public properties defined on the object. Can also contain methods to override the normal methods to create an anonymous subclass.
init: function ( mixin ) {
   this._queue = [];
   this._recent = null;
   this.activeConnections = 0;

   IOQueue.parent.init.call( this, mixin );
 },

Method

O.IOQueue#send( request )

If the number of active requests is equal to the maximum allowed number of concurrent connections, the request will be queued, ignored or cause the most recent active request to abort as specified in the O.IOQueue#link property.

Parameters

requestO.HttpRequest

Returns

O.IOQueue Returns self.

send: function ( request ) {
   if ( this.get( 'activeConnections' ) >= this.get( 'maxConnections' ) ) {
     switch ( this.get( 'link' ) ) {
       case QUEUE:
         this._queue.push( request );
         /* falls through */
       case IGNORE:
         return this;
       case ABORT:
         this._recent.abort();
         break;
       default:
         throw new Error( 'Invalid O.IOQueue link type.' );
     }
   }

   this.increment( 'activeConnections', 1 );

   // If already set, presume it will bubble to us
   if ( !request.get( 'nextEventTarget' ) ) {
     request.set( 'nextEventTarget', this );
   }

   // Store reference in case we need to abort a request.
   this._recent = request.send();

   return this;
 },

Method

O.IOQueue#abort( request )

Abort the request if it is currently running, or remove it from the waiting queue if it has not yet run.

Parameters

requestO.HttpRequest

Returns

O.IOQueue Returns self.

abort: function ( request ) {
   this._queue.erase( request );
   request.abort();
   return this;
 },

Private Method

O.IOQueue#_complete( transport )

Cleans up any state set by the IOQueue methods on the Transport object and starts the next request in the queue, if any.

Parameters

transportTransport The transport object.
_complete: function ( event ) {
   var request = event.target;
   if ( this._recent === request ) {
     this._recent = null;
   }
   if ( request.get( 'nextEventTarget' ) === this ) {
     request.set( 'nextEventTarget', null );
   }
   this.increment( 'activeConnections', -1 );

   if ( this._queue.length ) {
     this.send( this._queue.shift() );
   }
 }.on( 'io:end' )
});

IOQueue.QUEUE = 1;
IOQueue.IGNORE = 2;
IOQueue.ABORT = 3;

NS.IOQueue = IOQueue;

}( O ) );
Animation
Application
Core
DataStore
DOM
DragDrop
Foundation
IO
Localisation
Selection
Parser
TimeZones
Storage
Touch
CollectionViews
UA
ContainerViews
ControlViews
PanelViews
View