jquery.deferred-queue / README

.. -*- restructuredtext -*-

In jQuery 1.5, jQuery has introduced a Deferred object in order to
better handle callbacks.

Along with Deferred, it introduced ``jQuery.when`` which allows, among
other things, for multiplexing deferreds (waiting on multiple
deferreds at the same time).

While this is very nice if all deferreds are available at the same
point, it doesn't really work if the resolution of a deferred can
generate more deferreds, or for collections of deferreds coming from
multiple sources (which may not be aware of one another).

Deferred.queue tries to be a solution to this. It is based on the
principle of FIFO multiple-producers multiple-consumers tasks queues,
such as Python's `queue.Queue`_. Any code with a reference to the
queue can add a promise to the queue, and the queue (which is a
promise itself) will only be resolved once all promises within are
resolved.

Quickstart
----------

Deferred.queue has a very simple life cycle: it is dormant when
created, it starts working as soon as promises get added to it (via
``.push``, or by providing them directly to its constructor), and as
soon as the last promise in the queue is resolved it resolves itself.

If any promise in the queue fails, the queue itself will be rejected
(without waiting for further promises).

Once a queue has been resolved or rejected, adding new promises to it
results in an error.

API
---

``jQuery.Deferred.queue([promises...])``
  Creates a new deferred queue. Can be primed with a series of promise
  objects.

``.push(promise...)``
  Adds promises to the queue. Returns the queue itself (can be
  chained).

  If the queue has already been resolved or rejected, raises an error.

``.then([doneCallbacks][, failCallbacks])``
  Promise/A ``then`` method.

``.done(doneCallbacks)``
  jQuery ``done`` extension to promise objects

``.fail(failCallbacks)``
  jQuery ``fail`` extension to promise objects

.. _queue.Queue:
    http://docs.python.org/dev/library/queue.html
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.