是的你可以。每个产量 - 用 dilay 返回新的承诺(在承诺中 - 你必须根据 httpRequest 回调触发解析或拒绝)
以这种方式尝试
co(function *(){
var a = yield new Promise(function(resolve, reject){
setTimeout(function () {
//rosolve or reject this promise in callback of httpRequest();
}, 1000)
});
var b = yield new Promise(function(resolve, reject){
setTimeout(function () {
//rosolve or reject this promise in callback of httpRequest();
}, 1000)
});
var c = yield new Promise(function(resolve, reject){
setTimeout(function () {
//rosolve or reject this promise in callback of httpRequest();
}, 1000)
});
var res = [a, b, c];
console.log(res);
}).catch(onerror);