Reputation: 21
My code:
function wrapper(generatorFunction) {
return function (...args) {
let generatorObject = generatorFunction(...args);
generatorObject.next();
return generatorObject;
};
}
const wrapped = wrapper(function* () {
console.log(`First input: ${yield}`);
return 'DONE';
});
wrapped();
I have a question regarding why the web console isn't printing First input
. Although yield
returns undefined.
Upvotes: 0
Views: 63
Reputation: 1533
The first time you do next(), it will execute till the first yield.
function wrapper(generatorFunction) {
return function (...args) {
let generatorObject = generatorFunction(...args);
generatorObject.next(); // Will Print till yield keyword => First Yield Call
console.log('About to pass in a value to First Input');
let done = generatorObject.next(42); // Will Print and Bring the next yielded value => First Input 22
console.log(done);
return generatorObject;
};
}
wrapped = wrapper(function* () {
console.log('First Yield Call');
console.log(`First input: ${yield}`);
return 'DONE';
});
wrapped();
Upvotes: 1