Comparing version 3.0.6 to 3.0.7
@@ -0,1 +1,5 @@ | ||
3.0.7 / 2016-07-14 | ||
================== | ||
- Wait for the last 'each' (in `find`) to `resume` or `close` before resolving the promise | ||
3.0.6 / 2016-07-11 | ||
@@ -2,0 +6,0 @@ ================== |
@@ -348,8 +348,16 @@ /* | ||
var didClose = false | ||
var didFinish = false | ||
var processing = 0 | ||
function close () { | ||
didClose = true | ||
processing -= 1 | ||
cursor.close() | ||
} | ||
function pause () { | ||
processing += 1 | ||
cursor.pause() | ||
} | ||
return new Promise(function (resolve, reject) { | ||
@@ -360,4 +368,4 @@ cursor.on('data', function (doc) { | ||
close: close, | ||
pause: cursor.pause.bind(cursor), | ||
resume: cursor.resume.bind(cursor) | ||
pause: pause, | ||
resume: resume | ||
}) | ||
@@ -367,7 +375,18 @@ } | ||
function resume () { | ||
processing -= 1 | ||
cursor.resume() | ||
if (processing === 0 && didFinish) { | ||
done() | ||
} | ||
} | ||
function done () { | ||
if (fn) { | ||
fn() | ||
didFinish = true | ||
if (processing <= 0) { | ||
if (fn) { | ||
fn() | ||
} | ||
resolve() | ||
} | ||
resolve() | ||
} | ||
@@ -374,0 +393,0 @@ |
{ | ||
"name": "monk", | ||
"version": "3.0.6", | ||
"version": "3.0.7", | ||
"main": "lib/monk.js", | ||
@@ -5,0 +5,0 @@ "tags": [ |
36292
1034