You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
670 B
JavaScript
34 lines
670 B
JavaScript
6 years ago
|
'use strict';
|
||
|
|
||
|
// async function* asyncIterator() {
|
||
|
// while (true) {
|
||
|
// const value = await this.next();
|
||
|
// if (!value) {
|
||
|
// await this.close();
|
||
|
// return;
|
||
|
// }
|
||
|
|
||
|
// 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;
|