Permalink
Browse files

callbacks should now be called correctly

  • Loading branch information...
1 parent cbfd12c commit ff473bc46ee8131a7b8e8976fa9f738e7b2072c1 @pkrumins committed Sep 15, 2010
Showing with 21 additions and 5 deletions.
  1. +21 −5 lib/cart.js
View
@@ -30,21 +30,35 @@ function Cart(options) {
sys.inherits(Cart, ConnectStore);
Cart.prototype.get = function (hash, fn) {
- this.db.get(hash, fn);
+ this.db.get(hash, function (err, val) {
+ if (err) throw err;
+ if (val) {
+ fn(null, val);
+ }
+ else {
+ fn();
+ }
+ })
};
Cart.prototype.set = function (hash, sess, fn) {
- this.db.set(hash, JSON.stringify(sess), fn);
+ this.db.set(hash, JSON.stringify(sess), function (err) {
+ if (err) throw err;
+ if (fn) fn();
+ });
};
Cart.prototype.destroy = function (hash, fn) {
- this.db.remove(hash, fn);
+ this.db.remove(hash, function (err) {
+ if (err) throw err;
+ if (fn) fn();
+ });
};
Cart.prototype.length = function (fn) {
process.nextTick(function () {
this.db.length(function (err, len) {
- fn(len);
+ fn(null, len);
});
});
};
@@ -54,7 +68,9 @@ Cart.prototype.clear = function (fn) {
function (err, key, value) {
this.db.remove(key);
},
- function () { fn() }
+ function () {
+ if (fn) fn()
+ }
);
};

0 comments on commit ff473bc

Please sign in to comment.