index.js
function async(makeGenerator) {
  return () => {
    const generator = makeGenerator(...arguments);

    function handle(result) {
      // result => { done: [Boolean], value: [Object] }
      if (result.done) {
        return Promise.resolve(result.value);
      }

      return Promise.resolve(result.value).then(res => {
        return handle(generator.next(res));
      }, err => {
        return handle(generator.throw(err));
      });
    }

    try {
      return handle(generator.next());
    } catch (ex) {
      return Promise.reject(ex);
    }
  };
}
function async(makeGenerator) {
  return () => {
    const generator = makeGenerator(...arguments);

    function handle(result) {
      // result => { done: [Boolean], value: [Object] }
      if (result.done) {
        return Promise.resolve(result.value);
      }

      return Promise.resolve(result.value).then(res => {
        return handle(generator.next(res));
      }, err => {
        return handle(generator.throw(err));
      });
    }

    try {
      return handle(generator.next());
    } catch (ex) {
      return Promise.reject(ex);
    }
  };
}
function async ( makeGenerator ) { return ( ) => { const generator = makeGenerator ( ... arguments ) ; function handle ( result ) { // result => { done: [Boolean], value: [Object] } if ( result . done ) { return Promise . resolve ( result . value ) ; } return Promise . resolve ( result . value ) . then ( res => { return handle ( generator . next ( res ) ) ; } , err => { return handle ( generator . throw ( err ) ) ; } ) ; } try { return handle ( generator . next ( ) ) ; } catch ( ex ) { return Promise . reject ( ex ) ; } } ; }
Returns a function that resolves any yielded promises inside the generator.
@param {Function} makeGenerator - the function to turn into an async generator/promise
@returns {Function} the function that will iterate over interior promises on each call when invoked
Returns a function that resolves any yielded promises inside the generator .