coify
v0.1.2
Published
Transform generator methods into co-wrapped functions
Downloads
4
Readme
coify
Transform generator methods into co-wrapped functions.
Installing
npm install --save coify
Examples
Plain JavaScript objects
const coify = require('coify');
function delay( n ) {
return new Promise(function( resolve, reject ) {
setTimeout( resolve, n );
});
}
let obj = {
*asyncStuff() {
yield delay( 500 );
return true;
}
};
module.exports = coify( obj );
// ...
obj.asyncStuff().then( console.log ); // `true`
Classes/Constructors
const coify = require('coify');
function delay( n ) {
return new Promise(function( resolve, reject ) {
setTimeout( resolve, n );
});
}
class Thing {
*asyncStuff() {
yield delay( 500 );
return true;
}
}
module.exports = coify( Thing );
// ...
const thing = new Thing();
thing.asyncStuff().then( console.log ); // `true`