cocb
cocb
let you use all your existing asynchronous functions that gets a "callback" in the form of
function(error, data)
in a sequential way using generators, all this without the need to promisify them.
So if you have a large scale project with lots of non-promised functions and you want to use a
co style library - you can use cocb
.
Installation
npm install cocb
Usage
cocb
is a function in the form: function(function* (function(Error, Object)))
, meaning:
cocb
must get a generator function, which gets a next
function which gets error and data.
So this next
function should be passed as the cb
for all your async functions.
cocb()
will return an object with a catch
function in the form: function(function(Error))
, meaning:
the catch
function should get an error handler function, this error handler will be called
whenever next()
has been called with an error.
Example
var cocb = ; { ;} { ;} ; /*Output:Fetching user: Joe@gamil.comGot user: { email: 'Joe@gamil.com', id: 1483834229291 }Fetching projects for user: 1483834229291Got projects: { id: 1483834229291, projects: [ 2, 4, 6 ] }*/
License
MIT