Last active
November 2, 2016 15:33
-
-
Save caub/ccb97961827a82a9b8d267f49389dfee to your computer and use it in GitHub Desktop.
coroutine
This file contains 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
module.exports = function(gen) { // coroutine, equivalent to https://github.com/tj/co | |
const it = gen(); | |
return Promise.resolve().then(function pump(v) { | |
const next = it.next(v); | |
if(next.done) return next.value; | |
return Promise.resolve(next.value).then(pump, it.throw.bind(it)); | |
}); | |
}; |
This file contains 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
{ | |
"name": "co", | |
"version": "0.0.1", | |
"description": "small coroutine function", | |
"main": "co.js", | |
"repository": { | |
"type": "git", | |
"url": "git@gist.github.com:ccb97961827a82a9b8d267f49389dfee.git" | |
}, | |
"author": "caub", | |
"license": "ISC", | |
"homepage": "https://gist.github.com/caub/ccb97961827a82a9b8d267f49389dfee" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment