var BaseStore = require('./index').Store,
    util = require('util');

function MemoryStore (options) {
  BaseStore.call(this, options);

  var modules = {};
  var last_seq = null;

  this.emit("ready");

  this.has = function (key, cb) {
    cb(null, !!modules[key] && !modules[key].deleted);
  };

  this.get = function (key, cb) {
    cb(null, modules[key] || null);
  };

  this.put = function (key, data, cb) {
    var insert = !modules[key] || modules[key].deleted;
    modules[key] = data;
    if (cb) cb(null, insert, data);
  };

  this.remove = function (key, cb) {
    var found = false;
    if (modules[key]) {
      modules[key].deleted = true;
      found = true;
    }
    if (cb) cb(null, found);
  };

  this.lastSeq = function (value, cb) {
    if (typeof value === 'function') {
      cb = value;
      value = null;
    }
    if (typeof value === 'number') {
      last_seq = value;
    }
    if (cb) cb(null, last_seq || 0);
  };

  function getMany (emit, done, deleted) {
    if (emit) {
      for (var id in modules) {
        if ((!deleted && !modules[id].deleted) || (deleted && modules[id].deleted)) {
          emit(null, id, modules[id]);
        }
      }
    }
    if (done) done();
  }

  this.getAll = function (emit, done) {
    getMany(emit, done, false);
  };

  this.getGraveyard = function (emit, done) {
    getMany(emit, done, true);
  };

  this.close = function (cb) {
    modules = {};
    last_seq = null;
    if (cb) cb();
  };

}

util.inherits(MemoryStore, BaseStore);

module.exports = MemoryStore;

@@ -227,32 +227,63 @@
  (key, cb) %7B%0A   
+ process.nextTick(function () %7B
  cb(null, !!modu
@@ -317,16 +317,20 @@
 eleted);
+ %7D);
 %0A  %7D;%0A%0A 
@@ -365,16 +365,47 @@
 b) %7B%0A   
+ process.nextTick(function () %7B
  cb(null
@@ -428,16 +428,20 @@
 %7C null);
+ %7D);
 %0A  %7D;%0A%0A 
@@ -563,32 +563,63 @@
 ata;%0A    if (cb)
+ process.nextTick(function () %7B
  cb(null, insert
@@ -626,16 +626,20 @@
 , data);
+ %7D);
 %0A  %7D;%0A%0A 
@@ -785,32 +785,63 @@
    %7D%0A    if (cb)
+ process.nextTick(function () %7B
  cb(null, found)
@@ -841,16 +841,20 @@
  found);
+ %7D);
 %0A  %7D;%0A%0A 
@@ -1049,24 +1049,55 @@
 %0A    if (cb)
+ process.nextTick(function () %7B
  cb(null, la
@@ -1109,16 +1109,20 @@
 q %7C%7C 0);
+ %7D);
 %0A  %7D;%0A%0A 
@@ -1175,24 +1175,148 @@
 if (emit) %7B%0A
+      var doEmit = function (id, module) %7B%0A        process.nextTick(function () %7B emit(null, id, modules%5Bid%5D); %7D);%0A      %7D;%0A
       for (v
@@ -1431,27 +1431,23 @@
         
-e
+doE
 mit(
-null, 
 id, modu
@@ -1498,13 +1498,29 @@
 ne) 
+process.nextTick(
 done
-(
 );%0A 
@@ -1766,19 +1766,35 @@
 if (cb) 
+process.nextTick(
 cb
-(
 );%0A  %7D;%0A

Use process.nextTick in Memory store