Skip to main content
1 of 5
Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60

###Throttled Request Queue

To compensate for 503 errors and provide a capable, albeit a bit slower, client library for the API, Soapi.js currently includes an integrated throttled request queue.

The queue is integrated into the library and is transparent, requiring no additional coding or consideration.

The current default queue interval is 300ms for all api endpoints other than api.stackoverflow.com, which does not demonstrate out-of-band throttling problems.

This means that, with the request queue and request cache, you may make requests with impunity and without concern for 503 errors or API abuse and all requests, except those to api.stackoverflow.com, will be transparently queued up and executed at an acceptable rate.

Requests that are cached are not subject to queue delays.

The request queue throttle interval can be adjusted from the current default of 300ms via the static Soapi.RequestQueue object e.g.

Soapi.RequestQueue.setInterval(intervalInMS);

As a convenient side effect of implementing a request queue, throttled or otherwise, is the ability to provide feedback when your application is busy requesting data. This capability is implemented via global 'event' handlers and can easily facilitate UI blocking or manipulation e.g. ajax loading mask or other visual cues.

You can find a simple example of this in StackUsers Lite

/******************************************************
* A cheap auto loading mask by overriding the queue events
* Whenever the queue goes active or complete, wait 100ms
* to make sure the event is not transient and then check
* the queue length and show/hide mask as indicated.
* could use jQuery/BlockUI
*/

Soapi.Events.onQueueActive = Soapi.Events.onQueueComplete = checkMask;

function checkMask()
{
    // want a little buffer to eliminate mask flicker
    window.setTimeout(function()
    {
        if (Soapi.RequestQueue.getLength() == 0)
        {
            unmask();
        }
        else
        {
            mask();
        };
    }, 100);
};

The outstanding throttle issues, 1, 2, 3, 4, are currently under review and upon resolution the default queue interval will be reduced to nil providing much more responsive api access while maintaining error free execution.

Sky Sanders
  • 12.1k
  • 3
  • 32
  • 60