masklinn avatar masklinn committed 26fca93

queue constructor takes the same arguments as .push

Comments (0)

Files changed (2)

src/jquery.deferred-queue.js

                 queueDeferred.resolve();
             }
 
-            return $.extend(queueDeferred.promise(), {
+            var promise = $.extend(queueDeferred.promise(), {
                 push: function () {
                     promises += 1;
                     $.when.apply(null, arguments).then(
                     return this;
                 }
             });
+            if (arguments.length) {
+                promise.push.apply(promise, arguments);
+            }
+            return promise;
         }
     });
 })(jQuery)
             start();
         });
     });
+    asyncTest("Add stuff to the constructor itself", 1, function () {
+        var d = $.Deferred(), v = 3, bob = $.Deferred();
+        var queue = $.Deferred.queue(d, v, bob)
+            .then(function () { resolved = true; });
+        d.resolve();
+        bob.resolve();
+        setTimeout(function () {
+            ok(resolved);
+            start();
+        });
+    });
+    asyncTest("My constructor is full of eels", 2, function () {
+        var d1 = $.Deferred(),
+            d2 = $.Deferred(),
+            d3 = $.Deferred();
+        var queue = $.Deferred.queue(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();
+        });
+    });
 });
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.