I have a thunk
called logInline (adapted from the Co documentation).
I notice the thunkified get
always seems to yield
an array. Is this by design? Is it thunkify
doing this, or is it a standard part of yield
?
var co = require('co'),
get = thunkify(request.get);
var logInline = co(function *(){
var google = yield get('http://google.com');
console.log(google[0].statusCode);
})
logInline()
Note the variable 'google' here is always an array. Why? Note that request.get
normally returns err, response
(ie, there are no arrays).
The script, BTW, returns 200
or whatever other response code google.com returns.
Alas the yield documentation is pretty sparse ATM.
Edit: Thunks don't always return arrays. Eg if var readFile = thunkify(fs.readFile);
:
var fileContents = yield readFile('myfile', 'utf8');
log(fileContents);
In this case, fileContents is not returned inside an array. So why was google inside an array? There seems to be something in thunkify controlling what the thunks return