Skip to content

Instantly share code, notes, and snippets.

@caub
Last active November 2, 2016 15:33
Show Gist options
  • 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": "[email protected]: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