Closed
Description
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