Execute the generator function or a generator
and return a promise.

@param {Function} fn
@return {Promise}
@api public
502257
function co(gen) {
  var ctx = this;
  var args = slice.call(arguments, 1)

  // we wrap everything in a promise to avoid promise chaining,
  // which leads to memory leak errors.
  // see https://github.com/tj/co/issues/180
  return new Promise(function(resolve, reject) {
    if (typeof gen === 'function') gen = gen.apply(ctx, args);
    if (!gen || typeof gen.next !== 'function') return resolve(gen);

    onFulfilled();

    /**
     * @param {Mixed} res
     * @return {Promise}
     * @api private
     */

    function onFulfilled(res) {
      var ret;
      try {
        ret = gen.next(res);
      } catch (e) {
        return reject(e);
      }
      next(ret);
    }

    /**
     * @param {Error} err
     * @return {Promise}
     * @api private
     */

    function onRejected(err) {
      var ret;
      try {
        ret = gen.throw(err);
      } catch (e) {
        return reject(e);
      }
      next(ret);
    }

    /**
     * Get the next value in the generator,
     * return a promise.
     *
     * @param {Object} ret
     * @return {Promise}
     * @api private
     */

    function next(ret) {
      if (ret.done) return resolve(ret.value);
      var value = toPromise.call(ctx, ret.value);
      if (value && isPromise(value)) return value.then(onFulfilled, onRejected);
      return onRejected(new TypeError('You may only yield a function, promise, generator, array, or object, '
        + 'but the following object was passed: "' + String(ret.value) + '"'));
    }
  });
}
432424
function( fn ){
      var self = this;
      var _p = self._private;
      var subsize = self.spreadSize(); // number of pass eles to handle in each thread
      var pass = _p.pass.shift().concat([]); // keep a copy
      var runPs = [];

      for( var i = 0; i < this.length; i++ ){
        var thread = this[i];
        var slice = pass.splice( 0, subsize );

        var runP = thread.pass( slice ).run( fn );

        runPs.push( runP );

        var doneEarly = pass.length === 0;
        if( doneEarly ){ break; }
      }

      return $$.Promise.all( runPs ).then(function( thens ){
        var postpass = new Array();
        var p = 0;

        // fill postpass with the total result joined from all threads
        for( var i = 0; i < thens.length; i++ ){
          var then = thens[i]; // array result from thread i

          for( var j = 0; j < then.length; j++ ){
            var t = then[j]; // array element

            postpass[ p++ ] = t;
          }
        }

        return postpass;
      });
    }
993975
function raco (genFn, opts) {
    if (!isGeneratorFunction(genFn)) {
      if (isFunction(genFn)) throw new Error('Generator function required')
      else if (!isGenerator(genFn)) return factory(genFn)
    }
    opts = Object.assign({}, _opts, opts)
    opts.Promise = null
    return _raco.call(this, genFn, null, null, opts)
  }
594304
function ( fn, context ) {

		// Initialize variables
		this.state = Promise.STATE.INITIALIZED;
		this.handlers = [];
		this.value = fn;

		// Rebind control functions to be run always on this promise
		this.resolve = this.resolve.bind( this );
		this.fulfill = this.fulfill.bind( this );
		this.reject = this.reject.bind( this );

		// Set fn and context
		if ( fn ) {
			if ( typeof fn !== 'function' ) throw new TypeError("fn is not a function");

			this.fn = fn;
			this.context = context || this;

			this.run();

		}

		return this;
	}
1023579
function spawn($gen) {
		$send  = array($gen, 'send');
		$throw = array($gen, 'throw');
		$run = function($fn, $in) use ($gen, $send, $throw, &$run) {
			try {
				while (true) {
					$val = Promise::interpret( $fn ? $fn($in) : $gen->current() );
					if ( ! $gen->valid() ) { $this->resolve( $fn == $throw ? null : $in); return; }
					if ( ! $val instanceof PromiseInterface ) {
						$fn = $send;  $in = $val;
					} else if ( $val->getState() === PromiseInterface::REJECTED ) {
						$fn = $throw; $in = GP\exception_for( GP\inspect($val)['reason'] );
					} else {
						$val->then(
							function($val) use($run, $send)  { $run( $send, $val ); },
							function($err) use($run, $throw) { $run( $throw, GP\exception_for($err) ); }
						);
						return;
					}
				}
			} catch (\Exception $e) {
				$this->reject($e);
			} catch (\Throwable $t) {
				$this->reject($t);
			}
		};
		if ( $gen instanceof \Generator ) {
			$run( null, null );
		} else {
			$this->resolve($gen);
		}
		if ( $this->getState() === PromiseInterface::FULFILLED )
			return $this->wait();
		return $this;
	}
1152546
function shouldRegenerate(node, state) {
  if (node.generator) {
    if (node.async) {
      // Async generator
      return state.opts.asyncGenerators !== false;
    } else {
      // Plain generator
      return state.opts.generators !== false;
    }
  } else if (node.async) {
    // Async function
    return state.opts.async !== false;
  } else {
    // Not a generator or async function.
    return false;
  }
}
335953
function(fn) {
  if (promisify.isPromise(fn))
    return fn;
  if (typeof fn !== 'function')
    return promisify.Promise.resolve(fn);
  return new Promise((resolve, reject) => {
    try {
      const o = fn();
      if (promisify.isPromise(o)) {
        o.then(v => resolve(v))
            .catch((e) => reject(e));
      } else resolve(o);
    } catch (e) {
      reject(e);
    }
  });
}
492769
function runUntilResolved(genInstance, nextArg) {
  try {
    let nextResult = genInstance.next(nextArg);
    if (nextResult.done) {
      return Promise.resolve(nextResult.value);
    } else {
      let v = nextResult.value;
      let fn = v.fn;
      let thisArg;
      if (fn instanceof Array) {
        thisArg = fn[0];
        fn = fn[1];
      }
      let args = v.args;

      if (fn == null || args == null) {
        throw new Error('`Episode7.run` requires using `Episode7.call` with every `yield`. '+
          'Check all of the `yield` expressions in [Function: '+genInstance.episode7Name+']');
      }

      // Iterate through the generator, handling
      // promises & nested generators.
      // Side-effect function is called without `this`.
      let sideEffect;
      if (isGeneratorFunction(fn)) {
        sideEffect = Promise.resolve()
          .then(function() {
            // Wrapped in `then` to promisify return value
            return run(fn, ...args)
          })
      } else {
        sideEffect = Promise.resolve()
          .then(function() {
            // Wrapped in `then` to promisify return value
            return fn.call(thisArg, ...args)
          })
      }
      return sideEffect
        .then(function(result) {
          return runUntilResolved(genInstance, result);
        })
    }

  } catch(error) {
    return Promise.reject(error);
  }
}
826078
function callPromise(fn, args) {
	return new Promise((resolve, reject) => {
		// promisified callback
		function callback(err,other) {
			// check if the 'err' is boolean, if so then this is a 'exists' callback special case
			if (err && (typeof err !== 'boolean')) return reject(err);
			// convert arguments to proper array, ignoring error argument
			let args = Array.prototype.slice.call(arguments, 1);
			// if arguments length is one or more resolve arguments as array,
			// otherwise resolve the argument as is.
			return resolve(args.length < 2 ? args[0] : args);
		}
		fn.apply(null, args.concat([callback]));
	});
}
77630
function wrapFn(fn) {

  var argCount = fn.length;

  if (argCount < 2) {
    // promise style worker
    return async function(context) {
      return await fn(context);
    };
  }

  if (argCount === 2) {
    // callback style worker
    return function(context) {

      return new Promise(function(resolve, reject) {
        try {
          fn(context, function(err, data) {
            if (err) {
              reject(err);
            } else {
              resolve(data);
            }
          });
        } catch (err) {
          reject(err);
        }
      });

    };
  }

  throw new Error('expected Promise or callback style fn');
}
693889
function execPromise (fn) {
  return new Promise(function (resolve) {
    resolve(fn(process.argv.slice(2)))
  }).then(onSuccess, onError)
}
228329
function chainPromises(...fns) {
  return [...fns].reduce(
    (result, fn) => result.then(fn),
    Promise.resolve()
  );
}
712184
function enqueue(pool, executeFunction) {
  return new Promise(function(resolve) {
    pool.queue.push(function() {
      return Promise.resolve().then(executeFunction).then(resolve);
    });
  });
}
472760
function (promise){
    		promise.success = function (fn) {
	            promise.then(fn);
	            return promise;
	        };

	        promise.error = function (fn) {
	            promise.then(null, fn);
	            return promise;
	        };
    	}
275866
function promisify(func) {
        return function(str, options) {
            var result,
                deferred = q.defer(),
                promise = deferred.promise;

            if (!_.isFunction(func)) {
                deferred.reject();
            }
            else {
                result = func(str, options);

                if (_.isBoolean(result)) {
                    promise = handleBoolean(result, deferred);
                }
                else if (_.isFunction(result.then)) {
                    promise = result;
                }

            }
            return promise;
        };
    }
21064
def return_future(fn):
    
    @wraps(fn)
    def decorated(*args, **kwargs):
        return gen.maybe_future(fn(*args, **kwargs))

    return decorated
28577
function flow(fn) {
  if (!isGenerator(fn)) {
    throw new Error(NOT_GENERATOR);
  }
  var gen = fn();
  next();
  function next(e, v) {
    var r = e ? gen.throw(e) : gen.next(v);
    if (!r.done) {
      if (isThunk(r.value)) {
        r.value(function(e, v){next(e, v);});
      } else if (isThunkArray(r.value)) {
        parallel(r.value, next);
      } else {
        next(new Error(NOT_THUNK));
      }
    }
  }
}