kad-memstore-thomas
Advanced tools
Comparing version 0.1.0 to 0.2.0
32
index.js
@@ -8,2 +8,4 @@ /** | ||
var ReadableStream = require('readable-stream'); | ||
var assert = require('assert'); | ||
var _ = require('lodash'); | ||
@@ -29,6 +31,11 @@ /** | ||
KadMemStore.prototype.get = function(key, callback) { | ||
assert(_.isString(key), 'key is not a valid string') | ||
assert(_.isFunction(callback), 'callback is not a valid function') | ||
var self = this; | ||
setImmediate(function getItem() { | ||
callback(null, self._store[key] || null); | ||
setImmediate(function() { | ||
if(self._store[key]) { | ||
callback(null, self._store[key]) | ||
} else { | ||
callback(new Error('Key not found')) | ||
} | ||
}); | ||
@@ -45,2 +52,5 @@ }; | ||
KadMemStore.prototype.put = function(key, value, callback) { | ||
assert(_.isString(key), 'key is not a valid string') | ||
assert(!callback || _.isFunction(callback), 'callback is not a valid function') | ||
assert(_.isString(value), 'value is not a valid string') | ||
this._store[key] = value; | ||
@@ -59,7 +69,15 @@ if(callback) { | ||
KadMemStore.prototype.del = function(key, callback) { | ||
delete this._store[key]; | ||
if(callback) { | ||
setImmediate(callback); | ||
assert(_.isString(key), 'key is not a valid string') | ||
assert(!callback || _.isFunction(callback), 'callback is not a valid function') | ||
if(!callback) { | ||
callback = function() {} | ||
} | ||
setImmediate(function() { | ||
if(this._store[key]) { | ||
delete this._store[key] | ||
callback() | ||
} else { | ||
callback(new Error('Key not found')) | ||
} | ||
}) | ||
}; | ||
@@ -66,0 +84,0 @@ |
{ | ||
"name": "kad-memstore-thomas", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "in-memory kad storage adapter for testing and simulation", | ||
@@ -30,4 +30,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"lodash": "^4.15.0", | ||
"readable-stream": "^2.0.5" | ||
} | ||
} |
15037
198
2
+ Addedlodash@^4.15.0
+ Addedlodash@4.17.21(transitive)