Skip to content

Commit 4a17c75

Browse files
committed
fix: Many un-returned promise (related to neumino#285)
Bluebird default behavior is to warn on un-returned promise. This PR fix many of those in cursor.js
1 parent f77d2ff commit 4a17c75

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/cursor.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Cursor.prototype._fetch = function() {
114114
var self = this;
115115
this._fetching = true;
116116

117-
var p = new Promise(function(resolve, reject) {
117+
return new Promise(function(resolve, reject) {
118118
self.connection._continue(self.token, resolve, reject);
119119
}).then(function(response) {
120120
self._push(response);
@@ -124,6 +124,7 @@ Cursor.prototype._fetch = function() {
124124
self._canFetch = false;
125125
self._pushError(error);
126126
})
127+
127128
}
128129

129130
Cursor.prototype._push = function(data) {
@@ -142,7 +143,7 @@ Cursor.prototype._push = function(data) {
142143
// Try to solve as many pending promises as possible
143144
Cursor.prototype._flush = function() {
144145
while ((this._pendingPromises.length > 0) && ((this._data.length > 0) || ((this._fetching === false) && (this._canFetch === false)))) {
145-
var fullfiller = this._pendingPromises.shift();
146+
var fullfiller = this._pendingPromises.shift();
146147
var resolve = fullfiller.resolve;
147148
var reject = fullfiller.reject;
148149

@@ -268,7 +269,7 @@ Cursor.prototype._each = function(callback, onFinish) {
268269
}
269270

270271
self._next().then(resolve).error(function(error) {
271-
// We can silence error when the cursor is closed as this
272+
// We can silence error when the cursor is closed as this
272273
if ((error.message !== 'You cannot retrieve data from a cursor that is closed.') &&
273274
(error.message.match(/You cannot call `next` on a closed/) === null)) {
274275
reject(error);
@@ -291,26 +292,26 @@ Cursor.prototype._eachAsyncInternal = function(callback, finalResolve, finalReje
291292

292293
var nextCb = function() {
293294
self._stackSize++;
294-
self._next().then(function(row) {
295+
return self._next().then(function(row) {
295296
if (self._stackSize <= MAX_CALL_STACK) {
296297
if (callback.length <= 1) {
297-
Promise.resolve(callback(row)).then(nextCb)
298+
return Promise.resolve(callback(row)).then(nextCb)
298299
}
299300
else {
300-
new Promise(function(resolve, reject) {
301+
return new Promise(function(resolve, reject) {
301302
return callback(row, resolve)
302303
}).then(nextCb);
303304
}
304305
}
305306
else {
306-
new Promise(function(resolve, reject) {
307+
return new Promise(function(resolve, reject) {
307308
setTimeout(function() {
308309
self._stackSize = 0;
309310
if (callback.length <= 1) {
310-
Promise.resolve(callback(row)).then(resolve).catch(reject);
311+
return Promise.resolve(callback(row)).then(resolve).catch(reject);
311312
}
312313
else {
313-
new Promise(function(resolve, reject) {
314+
return new Promise(function(resolve, reject) {
314315
return callback(row, resolve)
315316
}).then(resolve).catch(reject);
316317
}

0 commit comments

Comments
 (0)