In this article we’re going to go step-by-step. We’ll progressively modify a toy callback-based example towards a generator-based solution. The goal is for you to understand how the entire process works, from end to end.
Generators are a new concept in JavaScript, but not in programming. You might have used them in other languages like Python. If not, have no fear, we’re going to do a gentle intro.
Generators in ES6 are declared like functions, except they have an asterisk: function* ticketGenerator() {}
When you want a generator to provide a value and then pause you use the yield keyword. yield is like return in that it hands back a value, except the function pauses after yield is called.
Your new post is loading...