co-booster
co-booster
is a performance tuning version of co
. If you're already using co
, you can make it work more faster by changing only the module. Naturally, It's fully compatible with co
.
co
is Generator based control flow goodness for nodejs and the browser, using promises, letting you write non-blocking code in a nice-ish way. You can check out co
here.
This work is all thanks to tj who is the author of co
.
co
How to change from Just change the module. You don't need anything else.
//var co = require('co');var co = ; ;
Performance
-
co() - benchmark code
- Node 4.4.7 : 8% faster
- Node 6.9.1 : 12% faster
-
co.wrap() - benchmark code
- Node 4.4.7 : 3% faster
- Node 6.9.1 : 8% faster
-
koa@1 style - benchmark code
- Node 4.4.7 : 15% faster
- Node 6.9.1 : 32% faster
Platform Compatibility
co-booster
requires a Promise
implementation.
For versions of node < 0.11
and for many older browsers,
you should/must include your own Promise
polyfill.
When using node 0.10.x and lower or browsers without generator support, you must use gnode and/or regenerator.
When using node 0.11.x, you must use the --harmony-generators
flag or just --harmony
to get access to generators.
Node v4+ is supported out of the box, you can use co-booster
without flags or polyfills.
Installation
$ npm install co-booster
Associated libraries
Any library that returns promises work well with co-booster
.
- mz - wrap all of node's code libraries as promises.
View the wiki for more libraries.
Examples
var co = ; ; ; // errors can be try/catched; { // log any uncaught errors // co will not throw any errors you do not handle!!! // HANDLE ALL YOUR ERRORS!!! console;}
Yieldables
The yieldable
objects currently supported are:
- promises
- thunks (functions)
- array (parallel execution)
- objects (parallel execution)
- generators (delegation)
- generator functions (delegation)
Nested yieldable
objects are supported, meaning you can nest
promises within objects within arrays, and so on!
Promises
Thunks
Thunks are functions that only have a single argument, a callback.
Thunk support only remains for backwards compatibility and may
be removed in future versions of co-booster
.
Arrays
yield
ing an array will resolve all the yieldables
in parallel.
;
Objects
Just like arrays, objects resolve all yieldable
s in parallel.
;
Generators and Generator Functions
Any generator or generator function you can pass into co-booster
can be yielded as well. This should generally be avoided
as we should be moving towards spec-compliant Promise
s instead.
How to skip errors in unsupported objects
If you set skipUnsupportError
, co
will no longer throw errors for unsupported objects.
coskipUnsupportError = true; ;
API
co(fn*).then( val => )
Returns a promise that resolves a generator, generator function, or any function that returns a generator.
;
var fn = co.wrap(fn*)
Convert a generator into a regular function that returns a Promise
.
var fn = co; ;
License
MIT