Skip to content

Instantly share code, notes, and snippets.

@caub
Last active November 2, 2016 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caub/ccb97961827a82a9b8d267f49389dfee to your computer and use it in GitHub Desktop.
Save caub/ccb97961827a82a9b8d267f49389dfee to your computer and use it in GitHub Desktop.
coroutine
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));
});
};
{
"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