Skip to content

Commit 49c8cef

Browse files
daprahamianmbroadst
authored andcommitted
fix(async): rewrote asyncGenerator in node < 10 syntax
Fixes NODE-1922
1 parent 72e88ad commit 49c8cef

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

lib/async/async_iterator.js

+27-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
'use strict';
22

3-
async function* asyncIterator() {
4-
while (true) {
5-
const value = await this.next();
6-
if (!value) {
7-
await this.close();
8-
return;
9-
}
3+
// async function* asyncIterator() {
4+
// while (true) {
5+
// const value = await this.next();
6+
// if (!value) {
7+
// await this.close();
8+
// return;
9+
// }
10+
11+
// yield value;
12+
// }
13+
// }
1014

11-
yield value;
12-
}
15+
// TODO: change this to the async generator function above
16+
function asyncIterator() {
17+
const cursor = this;
18+
19+
return {
20+
next: function() {
21+
return Promise.resolve()
22+
.then(() => cursor.next())
23+
.then(value => {
24+
if (!value) {
25+
return cursor.close().then(() => ({ value, done: true }));
26+
}
27+
return { value, done: false };
28+
});
29+
}
30+
};
1331
}
1432

1533
exports.asyncIterator = asyncIterator;

0 commit comments

Comments
 (0)