summaryrefslogtreecommitdiff
path: root/addons/web/static/lib/jquery.deferred-queue
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/lib/jquery.deferred-queue')
-rw-r--r--addons/web/static/lib/jquery.deferred-queue/LICENSE21
-rw-r--r--addons/web/static/lib/jquery.deferred-queue/README59
-rw-r--r--addons/web/static/lib/jquery.deferred-queue/jquery.deferred-queue.js34
3 files changed, 114 insertions, 0 deletions
diff --git a/addons/web/static/lib/jquery.deferred-queue/LICENSE b/addons/web/static/lib/jquery.deferred-queue/LICENSE
new file mode 100644
index 00000000000..ee8cf44578c
--- /dev/null
+++ b/addons/web/static/lib/jquery.deferred-queue/LICENSE
@@ -0,0 +1,21 @@
+Copyright 2011 Xavier Morel. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are
+permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this list of
+ conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ of conditions and the following disclaimer in the documentation and/or other materials
+ provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY XAVIER MOREL ``AS IS'' AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/addons/web/static/lib/jquery.deferred-queue/README b/addons/web/static/lib/jquery.deferred-queue/README
new file mode 100644
index 00000000000..71d980199c9
--- /dev/null
+++ b/addons/web/static/lib/jquery.deferred-queue/README
@@ -0,0 +1,59 @@
+.. -*- 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
diff --git a/addons/web/static/lib/jquery.deferred-queue/jquery.deferred-queue.js b/addons/web/static/lib/jquery.deferred-queue/jquery.deferred-queue.js
new file mode 100644
index 00000000000..7ef83342f77
--- /dev/null
+++ b/addons/web/static/lib/jquery.deferred-queue/jquery.deferred-queue.js
@@ -0,0 +1,34 @@
+(function ($) {
+ "use strict";
+ $.extend($.Deferred, {
+ queue: function () {
+ var queueDeferred = $.Deferred();
+ var promises = 0;
+
+ function resolve() {
+ if (--promises > 0) {
+ return;
+ }
+ setTimeout($.proxy(queueDeferred, 'resolve'), 0);
+ }
+
+ var promise = $.extend(queueDeferred.promise(), {
+ push: function () {
+ if (this.isResolved() || this.isRejected()) {
+ throw new Error("Can not add promises to a resolved "
+ + "or rejected promise queue");
+ }
+
+ promises += 1;
+ $.when.apply(null, arguments).then(
+ resolve, $.proxy(queueDeferred, 'reject'));
+ return this;
+ }
+ });
+ if (arguments.length) {
+ promise.push.apply(promise, arguments);
+ }
+ return promise;
+ }
+ });
+})(jQuery)