cofy
Cofy is a bridge connecting callback style object to sequential style in co or koa environment with one punch.
Installation
$ npm install cofy --save
NOTE: default prefix has changed to '$'.
Some examples
use cofy in redis.
'use strict';var co = ;var cofy = ;var redis = ; //enable redis to has a co ablitiy.cofy; //now we can use mysql in co var client = redis;;
use cofy in mysql.
'use strict';var co = ;var cofy = ;var mysql = ; //(felixge/node-mysql) has no extends entrance. so we can do this.var PoolConnection = ;var Pool = ;var PoolCluster = ; //enable mysql to has a co ablitiy.cofy;cofy;cofy; var pool = mysql;//now we can use mysql in co ; //use it in transaction;
use cofy in request.
'use strict';var request = ;var cofy = ;var co = ; var $request = cofy; ;
cofy nodejs
fs api:
'use strict';var cofy = ;var co = ; var fs = ;; //fs.exists callback function has no error. we call set `throwable` to false.fs$exists = cofyobjectfsexists false fs; ;
cofy API
class(constructor,[throwable],[methods],[prefix])
Enalbe a class or a object or a function to has co ability.
constructor
{function}
- cofy target.the constructor of the class;throwable
{bool}
- ifthrowable
is true the first argument of callback function arguments will be deemed as a exception.ifthrowable
is false,no exception will be throwed ,all arguments will be returned. default istrue
.methods
{array}
-Array
,if exists ,cofy will only cofy the methods in the target.prefix
{string}
- cofy will add function to the target(except target is function),the function name has a prefix. default is$
.
object(object,[throwable],[methods],[prefix],[context])
object
{function}
- cofy target.the constructor of the class;throwable
{bool}
- ifthrowable
is true the first argument of callback function arguments will be deemed as a exception.ifthrowable
is false,no exception will be throwed ,all arguments will be returned. default istrue
.context
{object}
- the function execute context.methods
{array}
-Array
,if exists ,cofy will only cofy the methods in the target.prefix
{string}
- cofy will add function to the target(except target is function),the function name has a prefix. default is$
.
fn(fn,[throwable],[context])
fn
{function}
- cofy a function;function(args , cb)
->yeild function(args)
throwable
{bool}
- ifthrowable
is true the first argument of callback function arguments will be deemed as a exception.ifthrowable
is false,no exception will be throwed ,all arguments will be returned. default istrue
.context
{object}
- the function execute context.