I am new to Koa, but set up an app that uses Kafka. I am using kafkaesque (https://github.com/pelger/Kafkaesque). I tried yield* kafkaesque.tearUp(). The result:
cb(err);
^
TypeError: undefined is not a function
I have also tried kafkaesque.tearUp(function *() {...}) but that does not work either - only the function () style callback works. Is it possible to work with these types of examples in a Koa way? I can deal with callbacks if needed, but cannot use work with the code now now because I need to call yield next after Kafka is connected (kafkaesque.tearUp) and a topic is set (kafkaesque.poll).
I finally was able to get kafkaesque working by using "thunking":
function tearUpThunk(kafka) {
return function(callback) {
kafka.tearUp(callback);
}
}
function pollThunk(kafka, options) {
return function(callback) {
kafka.tearUp(options, callback);
}
}
yield tearUpThunk(kafka) //Previously kafka.tearUp(function() {
yield pollThunk(kafka, options); // kafka.poll(options, function() { etc.
I simply needed to make sure each function returned a callback in this manner. Thanks to http://strongloop.com/strongblog/node-js-express-introduction-koa-js-zone/ for explaining this and other Koa patterns!
The node library thunkify can also make this easier (https://github.com/visionmedia/node-thunkify).