Js generator iterator

clipboard.png
6.5

clipboard.png
comment a b (). Next () is followed by a 6.5. Why does the second next () cause console.log (6.5) to be executed again? How to understand this problem?

Apr.01,2022

try changing the timer to an ordinary function


each call to the generator function generates a new iterator . You call b () twice, so you generate two new iterators, each of which is unassociated and executes independently. You may mean that you want to execute the same iterator twice instead of generating two iterators, both once:

function a () {
  function * b () {
    yield setTimeout(() => {
      console.log(6.5)
    }, 5000)
    yield 2
  }
  let iterator = b()
  iterator.next()
  iterator.next()
}
a()

clipboard.png

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2c1e7-2bad1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2c1e7-2bad1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?