rethinkdbdash
Advanced tools
Comparing version 2.2.3 to 2.2.4
@@ -298,4 +298,17 @@ var net = require('net'); | ||
// We save the current resolve function because we are going to call cursor._fetch before resuming the user's yield | ||
currentResolve = self.metadata[token].resolve; | ||
currentReject = self.metadata[token].reject; | ||
var done = false; | ||
if (typeof self.metadata[token].resolve !== 'function') { | ||
// According to issues/190, we can get a SUCESS_COMPLETE followed by a | ||
// SUCCESS_PARTIAL when closing an feed. So resolve/reject will be undefined | ||
// in this case. | ||
currentResolve = self.metadata[token].endResolve; | ||
currentReject = self.metadata[token].endReject; | ||
if (typeof currentResolve === 'function') { | ||
done = true; | ||
} | ||
} | ||
else { | ||
currentResolve = self.metadata[token].resolve; | ||
currentReject = self.metadata[token].reject; | ||
} | ||
@@ -394,3 +407,3 @@ // We need to delete before calling cursor._push | ||
else { // That was a continue query | ||
currentResolve({done: false, response: response}); | ||
currentResolve({done: done, response: response}); | ||
} | ||
@@ -427,3 +440,5 @@ } | ||
// We need to keep the options in the else statement, so we clean it inside the if/else blocks | ||
delete self.metadata[token]; | ||
if (typeof self.metadata[token].endResolve !== 'function') { | ||
delete self.metadata[token]; | ||
} | ||
} | ||
@@ -442,4 +457,10 @@ else if ((self.metadata[token].options.stream === true || self.r._options.stream === true)) { | ||
// We need to keep the options in the else statement, so we clean it inside the if/else blocks | ||
delete self.metadata[token]; | ||
// We need to keep the options in the else statement, | ||
// so we clean it inside the if/else blocks (the one looking | ||
// if a cursor was already created) | ||
if (typeof self.metadata[token].endResolve !== 'function') { | ||
// We do not want to delete the metadata if there is an END query waiting | ||
delete self.metadata[token]; | ||
} | ||
} | ||
@@ -457,9 +478,18 @@ else { | ||
} | ||
delete self.metadata[token]; | ||
if (typeof self.metadata[token].endResolve !== 'function') { | ||
delete self.metadata[token]; | ||
} | ||
}).error(currentReject) | ||
} | ||
done = true; | ||
cursor._push({done: true, response: response}); | ||
} | ||
else { // That was a continue query | ||
currentResolve({done: true, response: response}); | ||
// If there is a pending STOP query we do not want to close the cursor yet | ||
done = true; | ||
if (typeof self.metadata[token].endResolve === 'function') { | ||
done = false; | ||
} | ||
currentResolve({done: done, response: response}); | ||
} | ||
@@ -479,3 +509,2 @@ } | ||
} | ||
} | ||
@@ -482,0 +511,0 @@ |
@@ -27,2 +27,3 @@ var Promise = require('bluebird'); | ||
this.next = this._next; | ||
this._emittedEnd = false; | ||
} | ||
@@ -179,2 +180,5 @@ | ||
this._canFetch = false; | ||
if (this._eventEmitter) { | ||
this._eventEmitter.emit('end'); | ||
} | ||
} | ||
@@ -201,3 +205,10 @@ | ||
else { // since v0_4 (RethinkDB 2.0) we can (must) force a STOP request even if a CONTINUE query is pending | ||
self.connection._end(self.token, resolve, reject); | ||
var endCallback = function() { | ||
if (self._eventEmitter && (self._emittedEnd === false)) { | ||
self._emittedEnd = true; | ||
self._eventEmitter.emit('end'); | ||
} | ||
resolve(); | ||
} | ||
self.connection._end(self.token, endCallback, reject); | ||
} | ||
@@ -336,10 +347,8 @@ }).nodeify(callback); | ||
setImmediate(function() { | ||
if ((self._type === 'feed') || (self._type === 'atomFeed')) { | ||
self._each(self._eachCb.bind(self)); | ||
} | ||
else { | ||
self._each(self._eachCb.bind(self), function() { | ||
self._each(self._eachCb.bind(self), function() { | ||
if (self._emittedEnd === false) { | ||
self._emittedEnd = true; | ||
self._eventEmitter.emit('end'); | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
@@ -346,0 +355,0 @@ } |
{ | ||
"name": "rethinkdbdash", | ||
"version": "2.2.3", | ||
"version": "2.2.4", | ||
"description": "A Node.js driver for RethinkDB with promises and a connection pool", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
820417
25030