From 4a6a9ff36da82f18ce90b617a791b9078d01c263 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Sat, 13 Apr 2019 16:55:32 +0200 Subject: [PATCH 1/2] handle next call debouncing --- index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9ef8133..c92f5c8 100644 --- a/index.js +++ b/index.js @@ -13,8 +13,12 @@ function toReadable (iterator, opts) { readable.destroy(err) } + let curNext async function next () { - const { value, done } = await iterator.next() + if (curNext) return curNext + const { value, done } = await (curNext = iterator.next()) + curNext = null + if (done) { readable.push(null) return From 903d18a3980c3610a3bdff70286ca828b4d3984c Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Sat, 13 Apr 2019 17:01:53 +0200 Subject: [PATCH 2/2] ensure no return value --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index c92f5c8..a3623a4 100644 --- a/index.js +++ b/index.js @@ -15,10 +15,12 @@ function toReadable (iterator, opts) { let curNext async function next () { - if (curNext) return curNext + if (curNext) { + await curNext + return + } const { value, done } = await (curNext = iterator.next()) curNext = null - if (done) { readable.push(null) return