generator-wrap
v2.0.0
Published
Wrapper for generators to transform them in coroutines.
Downloads
4
Maintainers
Readme
generator-wrap
Wrapper for generators to transform them in coroutines.
Installation
$ npm install generator-wrap
Example
var wrap = require('generator-wrap');
function someAsyncOperation() {
return new Promise(function(resolve, reject){
setTimeout(function(){
resolve(3.1415);
}, 1000);
});
}
wrap(function*(){
console.log('Hello World from a coroutine!');
var asyncObtainedValue = yield someAsyncOperation();
console.log('Async Value: '+asyncObtainedValue);
})();
API
wrap(generatorFunction)
Wraps the generator in a function that is returned. When the function is executed, yielded values are treated as promises and their resolved values or their rejected errors are passed back in the generator.
License
MIT