Skip to content

Commit

Permalink
callbacks should now be called correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
pkrumins committed Sep 15, 2010
1 parent cbfd12c commit ff473bc
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions lib/cart.js
Expand Up @@ -30,21 +30,35 @@ function Cart(options) {
sys.inherits(Cart, ConnectStore); sys.inherits(Cart, ConnectStore);


Cart.prototype.get = function (hash, fn) { 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) { 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) { 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) { Cart.prototype.length = function (fn) {
process.nextTick(function () { process.nextTick(function () {
this.db.length(function (err, len) { this.db.length(function (err, len) {
fn(len); fn(null, len);
}); });
}); });
}; };
Expand All @@ -54,7 +68,9 @@ Cart.prototype.clear = function (fn) {
function (err, key, value) { function (err, key, value) {
this.db.remove(key); this.db.remove(key);
}, },
function () { fn() } function () {
if (fn) fn()
}
); );
}; };


0 comments on commit ff473bc

Please sign in to comment.