如何实现一个异步设置body的问题 ~~·
app.use(function*() {
setTimeout(function(){
// 在这里设置body
this.body = '111111'
}.bind(this),1000)
});
app.use(function*() {
this.body = yield fun();
});
function fun(){
return function(cb){
setTimeout(function(){
var bodyvalue = "111111",
err = null ;
cb(err,bodyvalue);
},1000);
return ""
}
}
看懂Co框架的实现才能弄懂koa回调的原理
app.use(function*() {
yield function(cb){
setTimeout(function(){
cb();
this.body = 100
}.bind(this),1000)
};
});
app.use(function*() {
var _this=this;
setTimeout(function(){
// 在这里设置body
this.body = '111111'
}.bind(this),1000)
});
都用koa了还不知道yield?!