src/utils/co.js
function exec(gen) {
  return new Promise((resolve, reject) => {
    const step = (value, rejection) => {
      let next;

      try {
        if (rejection)
          next = gen.throw(value);
        else
          next = gen.next(value);
      } catch (e) {
        reject(e);
        return;
      }

      if (next.done) {
        resolve(next.value);
        return;
      }

      if (!isPromise(next.value)) {
        step(next.value, false);
        return;
      }

      // eslint-disable-next-line no-use-before-define
      next.value.then(succeed, fail);
    };

    const succeed = (value) => {
      step(value, false);
    };

    const fail = (value) => {
      step(value, true);
    };

    step(undefined, false);
  });
}
function exec(gen) {
  return new Promise((resolve, reject) => {
    const step = (value, rejection) => {
      let next;

      try {
        if (rejection)
          next = gen.throw(value);
        else
          next = gen.next(value);
      } catch (e) {
        reject(e);
        return;
      }

      if (next.done) {
        resolve(next.value);
        return;
      }

      if (!isPromise(next.value)) {
        step(next.value, false);
        return;
      }

      // eslint-disable-next-line no-use-before-define
      next.value.then(succeed, fail);
    };

    const succeed = (value) => {
      step(value, false);
    };

    const fail = (value) => {
      step(value, true);
    };

    step(undefined, false);
  });
}
function exec ( gen ) { return new Promise ( ( resolve , reject ) => { const step = ( value , rejection ) => { let next ; try { if ( rejection ) next = gen . throw ( value ) ; else next = gen . next ( value ) ; } catch ( e ) { reject ( e ) ; return ; } if ( next . done ) { resolve ( next . value ) ; return ; } if ( ! isPromise ( next . value ) ) { step ( next . value , false ) ; return ; } // eslint-disable-next-line no-use-before-define next . value . then ( succeed , fail ) ; } ; const succeed = ( value ) => { step ( value , false ) ; } ; const fail = ( value ) => { step ( value , true ) ; } ; step ( undefined , false ) ; } ) ; }
Execute an instantiated generator.
@param {Generator} gen
@returns {Promise}
Execute an instantiated generator .