ES6。我正在学习es6中引入的生成器。这是我的app.js当我运行节点app.js什么都没打印。没有打印日志。这是我的代码
'use strict';
let sequence;
const run = generator =>{
sequence = generator();
}
const resume = (val) => {
sequence.next(val);
}
const async = {
run,
resume
}
const pause = delay => {
setTimeout(() => {
console.log('++++++PAUSED FOR 500 MS++++++++++');
async.resume(1000);
} , delay);
}
function* generatorFunction(){
console.log('start***** ');
var value = yield pause(500);
console.log('middle***** ' + value);
value = yield pause(500);
console.log('end***** '+ value);
}
async.run(generatorFunction);
我需要快速帮助
答案 0 :(得分:1)
我认为你必须调用sequence.next();
const run = generator =>{
sequence = generator();
sequence.next();
}
运行函数中的,以便生成器可以开始查找第一个yield语句