Comparing version 0.8.4 to 0.8.5
@@ -310,3 +310,3 @@ var async = require('async'); | ||
if (err) { | ||
closeStreams(streams); | ||
destroyStreams(streams); | ||
return callback(err); | ||
@@ -333,3 +333,3 @@ } | ||
if (err) { | ||
closeStreams(streams); | ||
destroyStreams(streams); | ||
return callback(err); | ||
@@ -342,2 +342,7 @@ } | ||
}; | ||
function destroyStreams(streams) { | ||
for (var id in streams) { | ||
streams[id].destroy(); | ||
} | ||
} | ||
@@ -344,0 +349,0 @@ Backend.prototype.queryFetch = function(agent, index, query, options, callback) { |
@@ -1,2 +0,1 @@ | ||
var assert = require('assert'); | ||
var inherits = require('util').inherits; | ||
@@ -81,6 +80,6 @@ var Readable = require('stream').Readable; | ||
// it with the getOps result. | ||
var d; | ||
var op; | ||
var queue = []; | ||
while (d = this.read()) { | ||
queue.push(d); | ||
while (op = this.read()) { | ||
queue.push(op); | ||
} | ||
@@ -90,16 +89,18 @@ | ||
for (var i = 0; i < ops.length; i++) { | ||
d = ops[i]; | ||
assert.equal(d.v, v); | ||
op = ops[i]; | ||
var err = checkOpVersion(op, v); | ||
if (err) return this.push({error: err}); | ||
v++; | ||
// console.log("stream push from preloaded ops", d); | ||
this.push(d); | ||
// console.log("stream push from preloaded ops", op); | ||
this.push(op); | ||
} | ||
// Then all the ops between then and now.. | ||
for (i = 0; i < queue.length; i++) { | ||
d = queue[i]; | ||
if (d.v >= v) { | ||
assert.equal(d.v, v); | ||
op = queue[i]; | ||
if (op.v >= v) { | ||
var err = checkOpVersion(op, v); | ||
if (err) return this.push({error: err}); | ||
v++; | ||
// console.log("stream push from early stream", d); | ||
this.push(d); | ||
// console.log("stream push from early stream", op); | ||
this.push(op); | ||
} | ||
@@ -111,1 +112,11 @@ } | ||
}; | ||
function checkOpVersion(op, v) { | ||
if (op.v === v) return; | ||
return { | ||
code: 5000, | ||
message: 'subscribe stream.pack op version inconsistent', | ||
op: op, | ||
v: v | ||
}; | ||
} |
{ | ||
"name": "sharedb", | ||
"version": "0.8.4", | ||
"version": "0.8.5", | ||
"description": "JSON OT database backend", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
238444
3687