0.1.2 • Published 8 years ago

coify v0.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

coify

Build Status

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`
0.1.2

8 years ago

0.1.1

9 years ago

0.1.0

9 years ago