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

co-callback

build status

callback friendly co for generator async control flow

Example

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

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

cocb.run(function*(){

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

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

    console.log(txt);

});

This simply outputs package.json concatenated with index.js

API

cocb.run(fn*, callback)

Run the generator function, callback when finished.

cocb.isGeneratorFunction(v)

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...
});

cocb.run(function*(){

    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

License

MIT

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

Copyright 2014 - 2017 © taobao.org |