Skip to content

Commit

Permalink
Merge pull request #2 from guybedford/read-debounce
Browse files Browse the repository at this point in the history
Handle next call debouncing
  • Loading branch information
mcollina authored Apr 15, 2019
2 parents 496a375 + 903d18a commit 27ef8f5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ function toReadable (iterator, opts) {
readable.destroy(err)
}

let curNext
async function next () {
const { value, done } = await iterator.next()
if (curNext) {
await curNext
return
}
const { value, done } = await (curNext = iterator.next())
curNext = null
if (done) {
readable.push(null)
return
Expand Down

0 comments on commit 27ef8f5

Please sign in to comment.