When should we use generators in ES6?
Generator functions provide a powerful alternative: they allow you to define an iterative algorithm by writing a single function whose execution is not continuous. Generator functions are written using the function* syntax. When called, generator functions do not initially execute their code.
You can also see this link for help-
https://www.geeksforgeeks.org/explain-the-generator-function-in-es6/#:~:text=The%20ES6%20generator%20is%20a,execution%20of%20a%20called%20function.