Permalink
Browse files

added a gracefull shutdown option

  • Loading branch information...
1 parent 80d7807 commit d54237bdbfe10b4c67bea9fbd473fe43debcdb65 @Pita committed Aug 17, 2011
Showing with 19 additions and 7 deletions.
  1. +13 −6 CacheAndBufferLayer.js
  2. +5 −0 CloneAndAtomicLayer.js
  3. +1 −1 package.json
@@ -82,12 +82,6 @@ exports.database = function(wrappedDB, settings, logger)
//set the flushing flag to false, this flag shows that there is a flushing action happing at the moment
this.isFlushing = false;
-
- //ensure the buffer is flushed before the application ends
- process.on('exit', function ()
- {
- flush(this);
- });
};
/**
@@ -123,6 +117,14 @@ exports.database.prototype.close = function(callback)
}
/**
+ Calls the callback the next time all buffers are flushed
+*/
+exports.database.prototype.doShutdown = function(callback)
+{
+ this.shutdownCallback = callback;
+}
+
+/**
Gets the value trough the wrapper.
*/
exports.database.prototype.get = function(key, callback)
@@ -470,6 +472,11 @@ function flush (db, callback)
db.isFlushing = false;
});
}
+ //the writing buffer is empty and there is a shutdown callback, call it!
+ else if(db.shutdownCallback != null)
+ {
+ db.shutdownCallback();
+ }
}
function clone(obj)
@@ -52,6 +52,11 @@ exports.database.prototype.init = function(callback)
Wrapper functions
*/
+exports.database.prototype.doShutdown = function(callback)
+{
+ this.db.doShutdown(callback);
+}
+
exports.database.prototype.get = function (key, callback)
{
this.channels.emit(key, {"db": this.db, "type": "get", "key": key, "callback": callback});
View
@@ -14,5 +14,5 @@
"log4js" : "0.3.7"
},
"main" : "./CloneAndAtomicLayer",
- "version" : "0.0.15"
+ "version" : "0.1.0"
}

0 comments on commit d54237b

Please sign in to comment.