co-simple
v1.0.1
Published
Coroutines from generator functions
Downloads
6
Maintainers
Readme
co-simple.js
Coroutines from generator functions
Current status
What's it for?
Very simple coroutine wrapper. No cruft, no dependencies, no funny business!
Compatible replacement for async/await
for versions of Node which don't support async/await natively.
All the other implementations I could find on NPM either include a load of extraneous features, or (unbelievably) are buggy. co is great, but includes features which async/await doesn't.
This implementation is identical to the code babel produces when transpiling async/await
.
So, if you're on a version of Node which doesn't support async/await, you can use this now, and then safely replace co(function*() {})
with async function() {}
once you update to a version which supports async/await natively.
Usage
const co = require('co-simple');
const foo = co( function*(a, b, c) {
const res = yield Promise.resolve(a * b * c);
return res;
} );
...is identical to...
const foo = async function(a, b, c) {
const res = await Promise.resolve(a * b * c);
return res;
};
Requires Promise
to be available in global scope, and support for generator functions (Node 4+).
Tests
Use npm test
to run the tests. Use npm run cover
to check coverage.
Changelog
See changelog.md
Issues
If you discover a bug, please raise an issue on Github. https://github.com/overlookmotel/co-simple/issues
Contribution
Pull requests are very welcome. Please:
- ensure all tests pass before submitting PR
- add an entry to changelog
- add tests for new features
- document new functionality/API additions in README