Wrapper for generators to transform them in coroutines.
Installation
$ npm install generator-wrap
Example
var wrap =require('generator-wrap');
functionsomeAsyncOperation(){
returnnewPromise(function(resolve,reject){
setTimeout(function(){
resolve(3.1415);
},1000);
});
}
wrap(function*(){
console.log('Hello World from a coroutine!');
var asyncObtainedValue =yieldsomeAsyncOperation();
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.