Skip to content

Commit 263aed2

Browse files
committed
Change the promises order of the eachBatch method to allow querying while executing the callback on the previous result as the same time.
1 parent d04bc13 commit 263aed2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/ParseQuery.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -923,18 +923,21 @@ class ParseQuery {
923923
}
924924

925925
let finished = false;
926+
let previousResults = [];
926927
return continueWhile(() => {
927928
return !finished;
928929
}, () => {
929-
return query.find(findOptions).then((results) => {
930-
return Promise.resolve(callback(results)).then(() => {
931-
if (results.length >= query._limit) {
932-
query.greaterThan('objectId', results[results.length - 1].id);
933-
} else {
930+
return Promise.all([
931+
query.find(findOptions),
932+
Promise.resolve(callback(previousResults))])
933+
.then(([results]) => {
934+
if (results.length == 0) {
934935
finished = true;
936+
} else {
937+
query.greaterThan('objectId', results[results.length - 1].id);
938+
previousResults = results;
935939
}
936940
});
937-
});
938941
});
939942
}
940943

0 commit comments

Comments
 (0)