function* showHelloWorld() {
let _s = '';
_s += yield p1;
_s += ' ';
_s += yield p2;
console.log(_s); //hello world
}
function p1(cb_) {
setTimeout(() => {
cb_('hello');
}, 1000);
}
function p2(cb_) {
setTimeout(() => {
cb_('world');
}, 1000);
}
function forof(it_, data_) {
const _obj = it_.next(data_);
if (!_obj.done) {
_obj.value(res_ => forof(it_, res_));
}
}
forof(showHelloWorld());
没有用到promise