// define the generator function
function *foo(x) {
var y = x * (yield);
return y;
}
// create the iterable to control the generator and pass in 6
var it = foo(6);
// start the generator, letting it run until the yield, so to var y = 6 * ...
it.next();
// unpause the generator, passing 7 to the waiting yield, and letting it run until the end
// capture the return value in res
var res = it.next(7);
res // {value: 42, done: true}
Created
June 12, 2018 12:21
-
-
Save amysimmons/670ed152f290474d21cd07e643dcd8ec to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment