Skip to content

Override the next method of an asynchronous iterator doesn't work in v10 #21125

Closed
@celicoo

Description

@celicoo

Bug Report

Current Behavior
Override the next method of an asynchronous iterator object doesn't work in v10.

Input Code

const customIterator = {
  [Symbol.asyncIterator]() {
    return {
      next: this.next
    }
  },

  next() {
    console.log('outter')
    this.next = () => {
      console.log('inner')
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve({
            done: false,
            value: {}
          })
        }, 1000)
      })
    }
    return this.next()
  }
}

async function test() {
  for await (const x of customIterator) {}
}
test()

Expected behavior/code
The output should be outter printed, followed by multiple inner, but in fact, the looping always prints outter and then inner, repeatedly.

Expected:

outter
inner
inner
inner
inner
...

Reality:

outter
inner
outter
inner
outter
inner

Environment

  • Node/npm version: 10.3/ 5
  • OS: 10.13.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIssues that look for answers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions