From 49c8cef08edab7e90b9cf0c60a6afde7d8bd2c50 Mon Sep 17 00:00:00 2001 From: Dan Aprahamian Date: Wed, 3 Apr 2019 14:17:07 -0400 Subject: [PATCH] fix(async): rewrote asyncGenerator in node < 10 syntax Fixes NODE-1922 --- lib/async/async_iterator.js | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/lib/async/async_iterator.js b/lib/async/async_iterator.js index a8f2612963..6021aadf9e 100644 --- a/lib/async/async_iterator.js +++ b/lib/async/async_iterator.js @@ -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;