我想在 koa 控制器中传递一个请求,它的工作:
var s = require('through2')();
var req = http.request(url, function(res) {
res.pipe(s);
})
req.end(null);
s.on('close', function() {
console.log('has close');
});
this.body = s;
但是使用 thunk ,它似乎不起作用。
var s = stream();
yield thunk(url, s);
this.body = s;
这是thunk
:
var thunk = function (url, s) {
return function(callback) {
var req = http.request(url, function(res) {
res.pipe(s);
});
s.on('close', function() {
callback(null, null);
console.log('req inner close');
});
req.end(null);
}
}