Skip to content

Commit

Permalink
fix(async): rewrote asyncGenerator in node < 10 syntax
Browse files Browse the repository at this point in the history
Fixes NODE-1922
  • Loading branch information
daprahamian authored and mbroadst committed Apr 5, 2019
1 parent 72e88ad commit 49c8cef
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions lib/async/async_iterator.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
'use strict';

async function* asyncIterator() {
while (true) {
const value = await this.next();
if (!value) {
await this.close();
return;
}
// async function* asyncIterator() {
// while (true) {
// const value = await this.next();
// if (!value) {
// await this.close();
// return;
// }

// yield value;
// }
// }

yield value;
}
// TODO: change this to the async generator function above
function asyncIterator() {
const cursor = this;

return {
next: function() {
return Promise.resolve()
.then(() => cursor.next())
.then(value => {
if (!value) {
return cursor.close().then(() => ({ value, done: true }));
}
return { value, done: false };
});
}
};
}

exports.asyncIterator = asyncIterator;

0 comments on commit 49c8cef

Please sign in to comment.