Permalink
Browse files

Support alternate close error on Queue

  • Loading branch information...
1 parent d55e6f8 commit ea9aae2e04e28f3e4f56305179b55154aaa9dc70 @kriskowal committed Feb 5, 2013
Showing with 38 additions and 7 deletions.
  1. +6 −6 queue.js
  2. +32 −1 spec/queue-spec.js
View
@@ -17,15 +17,15 @@ function Queue() {
get: function () {
var result = ends.promise.get("head");
ends.promise = ends.promise.get("tail");
- return result.fail(function (reason) {
- closed.resolve();
- throw reason;
+ return result.fail(function (error) {
+ closed.resolve(error);
+ throw error;
});
},
closed: closed.promise,
- close: function (reason) {
- reason = reason || new Error("Can't get value from closed queue");
- var end = {head: Q.reject(reason)};
+ close: function (error) {
+ error = error || new Error("Can't get value from closed queue");
+ var end = {head: Q.reject(error)};
end.tail = end;
ends.resolve(end);
return closed.promise;
View
@@ -1,6 +1,8 @@
var Q = require("../q");
var Queue = require("../queue");
+
+global.Q = Q;
require("./lib/jasmine-promise");
describe("queue", function () {
@@ -142,7 +144,36 @@ describe("queue", function () {
})
.catch(function (error) {
expect(error.message).toBe("Can't get value from closed queue");
- });
+ })
+ .then(function () {
+ return queue.closed;
+ })
+ .then(function (error) {
+ expect(error.message).toBe("Can't get value from closed queue");
+ })
+ });
+
+ it("should close with alternate error", function () {
+
+ var queue = Queue();
+ queue.close(new Error("Alternate reason"));
+
+ return Q.try(function () {
+ return queue.get();
+ })
+ .catch(function (error) {
+ expect(error.message).toBe("Alternate reason");
+ return queue.get();
+ })
+ .catch(function (error) {
+ expect(error.message).toBe("Alternate reason");
+ })
+ .then(function () {
+ return queue.closed;
+ })
+ .then(function (error) {
+ expect(error.message).toBe("Alternate reason");
+ })
});
});

0 comments on commit ea9aae2

Please sign in to comment.