Resolve then with its promise.
@private
@param  {Yaku} p
@param  {Thenable} x
@param  {Function} xthen
197477
function settleXthen (p, x, xthen) {
        // 2.3.3.3
        var err = genTryCatcher(xthen, x)(function (y) {
            // 2.3.3.3.3
            // 2.3.3.3.1
            x && (x = $null, settleWithX(p, y));
        }, function (r) {
            // 2.3.3.3.3
            // 2.3.3.3.2
            x && (x = $null, settlePromise(p, $rejected, r));
        });

        // 2.3.3.3.4.1
        if (err === $tryErr && x) {
            // 2.3.3.3.4.2
            settlePromise(p, $rejected, err.e);
            x = $null;
        }
    }
1039315
function then(onFulfilled, onRejected){
        var react = {
          ok:   typeof onFulfilled == 'function' ? onFulfilled : true,
          fail: typeof onRejected == 'function'  ? onRejected  : false
        };
        var promise = react.P = new (speciesConstructor(this, P))(function(res, rej){
          react.res = res;
          react.rej = rej;
        });
        aFunction(react.res);
        aFunction(react.rej);
        var record = this[RECORD];
        record.c.push(react);
        if(record.a)record.a.push(react);
        if(record.s)notify(record, false);
        return promise;
      }
471660
function handleThenable(promise, value) {
  var done, then;

  // Attempt to get the `then` method from the thenable (if it is a thenable)
  try {
    if (! (then = utils.thenable(value))) {
      return false;
    }
  } catch (err) {
    rejectPromise(promise, err);
    return true;
  }

  // Ensure that the promise did not attempt to fulfill with itself
  if (promise === value) {
    rejectPromise(promise, new TypeError('Circular resolution of promises'));
    return true;
  }

  try {
    // Wait for the thenable to fulfill/reject before moving on
    then.call(value,
      function(subValue) {
        if (! done) {
          done = true;

          // Once again look for circular promise resolution
          if (value === subValue) {
            rejectPromise(promise, new TypeError('Circular resolution of promises'));
            return;
          }

          resolvePromise(promise, subValue);
        }
      },
      function(subValue) {
        if (! done) {
          done = true;

          rejectPromise(promise, subValue);
        }
      }
    );
  } catch (err) {
    if (! done) {
      done = true;

      rejectPromise(promise, err);
    }
  }

  return true;
}
991498
function resolve(promise, x) {
  /*  sanity check arguments  */

  /*  [Promises/A+ 2.3.1]  */
  if (promise === x || promise.proxy === x) {
    promise.reject(new TypeError('cannot resolve promise with itself'));
    return;
  }
  /*  surgically check for a "then" method
    (mainly to just call the "getter" of "then" only once)  */


  var then;

  if (_typeof(x) === 'object' && x !== null || typeof x === 'function') {
    try {
      then = x.then;
    }
    /*  [Promises/A+ 2.3.3.1, 3.5]  */
    catch (e) {
      promise.reject(e);
      /*  [Promises/A+ 2.3.3.2]  */

      return;
    }
  }
  /*  handle own Thenables    [Promises/A+ 2.3.2]
    and similar "thenables" [Promises/A+ 2.3.3]  */


  if (typeof then === 'function') {
    var resolved = false;

    try {
      /*  call retrieved "then" method */

      /*  [Promises/A+ 2.3.3.3]  */
      then.call(x,
      /*  resolvePromise  */

      /*  [Promises/A+ 2.3.3.3.1]  */
      function (y) {
        if (resolved) return;
        resolved = true;
        /*  [Promises/A+ 2.3.3.3.3]  */

        if (y === x)
          /*  [Promises/A+ 3.6]  */
          promise.reject(new TypeError('circular thenable chain'));else resolve(promise, y);
      },
      /*  rejectPromise  */

      /*  [Promises/A+ 2.3.3.3.2]  */
      function (r) {
        if (resolved) return;
        resolved = true;
        /*  [Promises/A+ 2.3.3.3.3]  */

        promise.reject(r);
      });
    } catch (e) {
      if (!resolved)
        /*  [Promises/A+ 2.3.3.3.3]  */
        promise.reject(e);
      /*  [Promises/A+ 2.3.3.3.4]  */
    }

    return;
  }
  /*  handle other values  */


  promise.fulfill(x);
  /*  [Promises/A+ 2.3.4, 2.3.3.4]  */
}
642438
function asPromise (fn) {
  return new Promise((resolve, reject) => {
    fn((err, result) => {
      if (err) {
        return reject(err)
      }
      resolve(result)
    })
  })
}
699087
function doResolve(fn, self) {
  var done = false;
  try {
    fn(
      function(value) {
        if (done) { return; }
        done = true;
        resolve(self, value);
      },
      function(reason) {
        if (done) { return; }
        done = true;
        reject(self, reason);
      }
    );
  } catch (ex) {
    if (done) { return; }
    done = true;
    reject(self, ex);
  }
}
1307857
function when(promises) {
	promises = arrayify(promises);
	var whenPromise = new PromiseFactory();

	var pending = promises.length;
	var results = [];

	var resolve = function (i) {
		return function (val) {
			results[i] = val;
			pending--;

			if (pending === 0) {
				whenPromise.resolve(results);
			}
		};
	};

	promises.forEach(function (p, i) {
		if (!p || !p.then) return;

		p.then(resolve(i), whenPromise.reject);
	});

	return whenPromise.promise();
}
855426
function asPromise (val) {
	if (val && typeof val.then === 'function') {
		return val;
	}
	var deferred = new PromiseFactory();
	deferred.resolve(val);
	return deferred.promise();
}
693889
function execPromise (fn) {
  return new Promise(function (resolve) {
    resolve(fn(process.argv.slice(2)))
  }).then(onSuccess, onError)
}
544055
function promise (input, value) {
  value.then(val => {
    morph(val, input)
  }, reason => {
    input.emit('error', reason)
  })
}
731084
function processBranch (args, resolve, reject) {
  let condition = args.shift()
  let val = args.shift()
  let las = _.last(args)

  return Promise.resolve(condition)
    .then(c => {
      if (c === true) {
        return Promise.resolve(_.isFunction(val) ? val() : val)
          .then(resolve, reject)
      } else if (args.length === 1) {
        return Promise.resolve(_.isFunction(las) ? las() : las)
          .then(resolve, reject)
      } else {
        return processBranch(args, resolve, reject)
      }
    }, reject)
}
1334351
function sequence(promises) {
  var result = Promise.resolve();
  promises.forEach(function(promise,i) {
    result = result.then(promise);
  });
  return result;
}
1312486
function promise(p) {
        var me = this;

        var canHandlePromise =
            this.children.indexOf("completed") >= 0 &&
            this.children.indexOf("failed") >= 0;

        if (!canHandlePromise){
            throw new Error("Publisher must have \"completed\" and \"failed\" child publishers");
        }

        p.then(function(response) {
            return me.completed(response);
        }, function(error) {
            return me.failed(error);
        });
    }
207212
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 )
                                              + '"' ) );
        }
580858
function _singlePromise () {
  let  done, cancel;
  const x = new Promise ( (resolve, reject ) => { 
                                                  done   = resolve
                                                  cancel = reject
                                 })

   return { 
               promise    : x
             , done       : done 
             , cancel     : cancel
             , onComplete : _after(x)
           }
   }
941605
function makePromise(requestInstance, promiseFactoryFn) {

  // Resolver function wich assigns the promise (resolve, reject) functions
  // to the requestInstance
  function Resolver(resolve, reject) {
    this._resolve = resolve;
    this._reject = reject;
  }

  return promiseFactoryFn(Resolver.bind(requestInstance));
}
594980
function resolveSync(p, base, root) {
  if (!path.isAbsolute(p)) {
    p = path.resolve(path.resolve(root, base), p);
  }
  return p;
}