queued-chunk-store
Advanced tools
Comparing version 1.1.0 to 1.2.0
18
index.js
@@ -0,1 +1,2 @@ | ||
var async = require('async') | ||
module.exports = QueuedChunkStore | ||
@@ -28,8 +29,21 @@ | ||
if (isArray(queuedGetsAtIndex)) { | ||
var callbacks = []; | ||
for (var i = 0; i < queuedGetsAtIndex.length; i++) { | ||
var queuedGet = queuedGetsAtIndex[i]; | ||
self.store.get(index, queuedGet.opts, queuedGet.cb); | ||
(function(queuedGet) { | ||
callbacks.push(function (callback) { | ||
self.store.get(index, queuedGet.opts, function(err, buf) { | ||
queuedGet.cb(err, buf) | ||
callback(err, buf) | ||
}) | ||
}) | ||
})(queuedGet) | ||
} | ||
async.parallel(callbacks, function() { | ||
self.queuedGets[index] = [] | ||
if (cb) cb(null); | ||
}); | ||
return; | ||
} | ||
if (cb) cb(null); | ||
@@ -36,0 +50,0 @@ }) |
{ | ||
"name": "queued-chunk-store", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Queued .get for abstract-chunk-store compliant stores", | ||
@@ -31,3 +31,6 @@ "main": "index.js", | ||
"test": "node test" | ||
}, | ||
"dependencies": { | ||
"async": "^2.0.0-rc.3" | ||
} | ||
} |
35
test.js
@@ -26,5 +26,24 @@ var abstractTests = require('abstract-chunk-store/tests') | ||
t.deepEqual(buf, new Buffer('0123456789')) | ||
t.end() | ||
}) | ||
store.get(1, function(err, buf) { | ||
store.put(0, new Buffer('0123456789')) | ||
}) | ||
test('put then get', function (t) { | ||
var store = new Queued(Immediate(MemoryChunkStore(10))) | ||
store.put(0, new Buffer('0123456789'), function() { | ||
store.get(0, function(err, buf) { | ||
t.error(err) | ||
t.deepEqual(buf, new Buffer('0123456789')) | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
test('gets should be removed after put', function (t) { | ||
var store = new Queued(new MemoryChunkStore(10)) | ||
store.get(0, function(err, buf) { | ||
t.error(err) | ||
@@ -34,7 +53,15 @@ t.deepEqual(buf, new Buffer('0123456789')) | ||
store.put(0, new Buffer('0123456789')) | ||
store.get(0, function(err, buf) { | ||
t.error(err) | ||
t.deepEqual(buf, new Buffer('0123456789')) | ||
}) | ||
store.put(1, new Buffer('0123456789')) | ||
store.put(0, new Buffer('0123456789'), function() { | ||
t.equal(store.queuedGets[0].length, 0) | ||
t.end() | ||
store.destroy(function (err) { | ||
t.error(err) | ||
t.end() | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
6310
121
1
+ Addedasync@^2.0.0-rc.3
+ Addedasync@2.6.4(transitive)
+ Addedlodash@4.17.21(transitive)