Created
November 21, 2014 04:22
-
-
Save elrrrrrrr/4eb0fdadc59b2045e192 to your computer and use it in GitHub Desktop.
simple-co
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function co(generator) { | |
return function(fn) { | |
var gen = generator(); | |
function next(err, result) { | |
if(err){ | |
return fn(err); | |
} | |
var step = gen.next(result); | |
if (!step.done) { | |
step.value(next); | |
} else { | |
fn(null, step.value); | |
} | |
} | |
next(); | |
} | |
} | |
module.exports = co; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment