callback friendly `co` generator async control flow goodness
Last updated a year ago by farskipper .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install co-callback 
SYNC missed versions from official npm registry.


build status

callback friendly co for generator async control flow


var fs = require("fs");
var cocb = require("co-callback");

var readFileYieldable = cocb.wrap(fs.readFile);*(){

    var file1 = yield readFileYieldable("./package.json", "utf8");
    var file2 = yield readFileYieldable("./index.js", "utf8");

    return file1 + file2;
}, function(err, txt){



This simply outputs package.json concatenated with index.js

API*, callback)

Run the generator function, callback when finished.


return true if it is a generator function

cocb.wrap(fn_with_callback) or cocb.wrap(fn*)

Converts a callback function, or generator into one you can yield. (i.e. a Promise function - see co.wrap)

For example:

var foo = cocb.wrap(function(a, b, callback){
   // some callback async stuff...

var bar = cocb.wrap(function * (one, two){
   // some yield async stuff...

    yield foo("a", "b")
    yield bar(1, 2)

}, callback);

Promises are lies ;)

Promise hell is a real place, it's complicated, has hidden errors, and lies to you with a smile. Callbacks are simpler and naturally robust, but yes, it has a hell too.

As with any programming tool, you need learn, practice, and master. If you don't, you will waste a lot of time in hell.

escape callback hell

escape promise hell



Maintainers (1)
Today 0
This Week 0
This Month 6
Last Day 0
Last Week 1
Last Month 1
Dependencies (1)
  • co ^4.6.0
Dev Dependencies (2)
Dependents (1)

Copyright 2014 - 2016 © |