Obviously, the reason here is because of the async nature of on('data')
, and the combination of using yield, but how can I make this work? I tried "thunkifying" _this.req.on
, but to no avail. I'm still getting the hang of generators, yield and thunks but I'm a bit stumped here.
Is there any other clever solution without requiring another module dependency?
var thunkify = require('thunkify');
var request = thunkify(require('request'));
//...
if (['GET', 'DELETE'].indexOf(_this.req.method) === -1) {
_this.req.on('data', function(chunk) {
options.json = chunk.toString();
});
}
//...
var resp = yield request(options);
_this.body = resp[0].body;