Commits

masklinn committed c69a08d

Allow for multiple promises added in the same .push() call

Comments (0)

Files changed (2)

src/jquery.deferred-queue.js

             }
 
             return $.extend(queueDeferred.promise(), {
-                push: function (promise) {
+                push: function () {
                     promises += 1;
-                    $.when(promise).then(
+                    $.when.apply(null, arguments).then(
                         resolve, $.proxy(queueDeferred, 'reject'));
                     return this;
                 }
             start();
         });
     });
+    asyncTest("Push multiple deferreds a in a single call", 1, function () {
+        var d1 = $.Deferred(),
+            d2 = $.Deferred(),
+            d3 = $.Deferred();
+        queue.push(d1.promise(),
+                   d2.promise(),
+                   d3.promise())
+            .then(function () { resolved = true; });
+        d1.resolve();
+        d2.resolve();
+        d3.resolve();
+        setTimeout(function () {
+            ok(resolved);
+            start();
+        });
+    });
     asyncTest("Rejecting one of several deferreds", 2, function () {
         var d1 = $.Deferred(),
             d2 = $.Deferred(),
             start();
         });
     });
+    asyncTest("Rejecting one of several deferreds - simult", 2, function () {
+        var d1 = $.Deferred(),
+            d2 = $.Deferred(),
+            d3 = $.Deferred();
+        queue.push(d1.promise(),
+                   d2.promise(),
+                   d3.promise())
+            .then(function () { resolved = true; },
+                  function () { rejected = true; });
+        d1.resolve();
+        d2.reject();
+        d3.resolve();
+        setTimeout(function () {
+            ok(rejected);
+            ok(!resolved);
+            start();
+        });
+    });
     asyncTest("Accept non-promises as well", 1, function () {
         var d = $.Deferred(), v = 3;
         queue.push(d)