I've gotten some third party asynchronous functions to work with Koa through thunking, either by wrapping the function like so: var thunkedFunction = function(params) { return function(callback) { originalFunction(params, callback) }; )
or using the node thunkify library.
However when I try this with ntwitter's stream like so:
var streamThunk = thunkify(tw.stream);
var stream = yield streamThunk("statuses/filter", {track: track});
I get the following error: "Cannot read property stream_base of undefined".
Digging deeper into ntwitter (built on node-twitter) I see that the Twitter.prototype.stream function calls this.options.stream_base, and this.options is defined when I call it normally i.e. tw.stream(function(stream) {...});
but undefined when I thunk the function. Is there any reason that the function loses its scope when thunked, and is there a way to circumvent this?