generator-wrap

2.0.0 • Public • Published

generator-wrap Build Status

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

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i generator-wrap

      Weekly Downloads

      8

      Version

      2.0.0

      License

      MIT

      Last publish

      Collaborators

      • sqreept