this function will kick off the new chain of assertions on the setttled result of the promise
515261
function (resolved, val) {
                var should = (negate ?
                    (new Assertion(val)).not :
                    (new Assertion(val))
                );
                
                if (storedAssertions[0][0] !== 'throw' && !resolved) {
                    throw val;
                }
                
                var result = storedAssertions.reduce(function (accum, cur) {
                    // 'throw' must immediately follow 'eventually' if it is used
                    if (cur[0] === 'throw') {
                        // should.throw is a special case; it expects a function
                        // that it will then call to discern whether an error was thrown
                        // or not, but we have a (potentially) rejected value of a promise,
                        // so we need to wrap that value in a function for should.throw to call
                        var obj = accum.obj;
                        accum.obj = function () {
                            if (resolved) { return obj; }
                            else { throw obj; }
                        };
                    }
                    
                    // this block is separated from the above intentionally;
                    // the above deals with putting the data in the expected format,
                    // while this deals with whether or not to throw an error
                    if (cur[0] === 'throw') {
                        // these conditions are acceptable:
                        // resolved === true && negate === true - promise succeeded, throw check is negated
                        // resolved === false && negate !== true - promise rejected, throw check is not negated
                        if (resolved === !!accum.negate) {
                            caught = true;
                        } else {
                            throw new AssertionError({
                                message: 'Expected promise to be ' + (negate ? 'resolved' : 'rejected') +
                                    ' but instead it was ' + (resolved ? 'resolved' : 'rejected') + ' with ' + inspect(val),
                                actual: val
                            });
                        }
                    }
                    
                    if (cur.length === 1) {
                        // assertion was a getter, apply to current value
                        return accum[cur[0]];
                    } else {
                        // assertion was a function, apply to current value
                        return accum[cur[0]].apply(accum, cur[1]);
                    }
                }, should); // call .should on our resolved value to begin the assertion chain
                
                if (!resolved && !caught) {
                    throw new AssertionError({
                        message: 'Promise was rejected unexpectedly with ' + inspect(val),
                        actual: val
                    });
                }
                return result;
            }
298324
function (onFulfilled, onRejected) {
				var curr = this;
				var next = new api();                                    /*  [Promises/A+ 2.2.7]  */
				curr.onFulfilled.push(
					resolver(onFulfilled, next, "fulfill"));             /*  [Promises/A+ 2.2.2/2.2.6]  */
				curr.onRejected.push(
					resolver(onRejected,  next, "reject" ));             /*  [Promises/A+ 2.2.3/2.2.6]  */
				execute(curr);
				return next.proxy;                                       /*  [Promises/A+ 2.2.7, 3.3]  */
			}
872959
function assertContext() {
  return new Promise(function(resolve, reject) {
    // Check if we're in an active session
    let d = process.domain
    if (d == null ||
        d.context == null ||
        d.context.bardo == null) {
      // Begin the session before proceeding
      return begin().then((ctx) => {
        resolve(ctx)
      }).catch(reject)
    }

    // Continue onwards with our active domain
    return resolve(d.context.bardo)
  })
}
511914
function promisesWrapper(func) {
    return (options, callback) => {
        // options is an optional argument
        if (typeof options === 'function') {
            callback = options;
            options = undefined;
        }
        options = options || {};
        // just call the function otherwise wrap a promise around its execution
        if (typeof callback === 'function') {
            func(options, callback);
            return undefined;
        } else {
            return new Promise((fulfill, reject) => {
                func(options, (err, result) => {
                    if (err) {
                        reject(err);
                    } else {
                        fulfill(result);
                    }
                });
            });
        }
    };
}
72557
function fulfillPromise(promise, value) {
  if (promise.state !== PENDING) {return;}

  setValue(promise, value);
  setState(promise, UNFULFILLED);

  setImmediate(function() {
    setState(promise, FULFILLED);
    invokeFunctions(promise);
  });
}
179991
function(future,
                        fulfillCallbacks,
                        rejectCallbacks,
                        setValue,
                        setError,
                        setState) {
  var isResolved = false;

  var resolver = this;
  var fulfill = function(value) {
    // console.log("queueing fulfill with:", value);
    async(function() {
      setState("fulfilled");
      setValue(value);
      // console.log("fulfilling with:", value);
      fulfillCallbacks.pump(value);
    });
  };
  var reject = function(reason) {
    // console.log("queuing reject with:", reason);
    async(function() {
      setState("rejected");
      setError(reason);
      // console.log("rejecting with:", reason);
      rejectCallbacks.pump(reason);
    });
  };
  var resolve = function(value) {
    if (isThenable(value)) {
      value.then(resolve, reject);
      return;
    }
    fulfill(value);
  };
  var ifNotResolved = function(func, name) {
    return function(value) {
      if (!isResolved) {
        isResolved = true;
        func(value);
      } else {
        if (typeof console != "undefined") {
          console.error("Cannot resolve a Promise multiple times.");
        }
      }
    };
  };

  // Indirectly resolves the Promise, chaining any passed Promise's resolution
  this.resolve = ifNotResolved(resolve, "resolve");

  // Directly fulfills the future, no matter what value's type is
  this.fulfill = ifNotResolved(fulfill, "fulfill");

  // Rejects the future
  this.reject = ifNotResolved(reject, "reject");

  this.cancel  = function() { resolver.reject(new Error("Cancel")); };
  this.timeout = function() { resolver.reject(new Error("Timeout")); };

  if (underTest) {
    Object.defineProperties(this, {
      _isResolved: _readOnlyProperty(function() { return isResolved; }),
    });
  }

  setState("pending");
}
537714
function Promise(handler, parent) {
  var me = this;

  if (!(this instanceof Promise)) {
    throw new SyntaxError('Constructor must be called with the new operator');
  }

  if (typeof handler !== 'function') {
    throw new SyntaxError('Function parameter handler(resolve, reject) missing');
  }

  var _onSuccess = [];
  var _onFail = [];

  // status
  this.resolved = false;
  this.rejected = false;
  this.pending = true;

  /**
   * Process onSuccess and onFail callbacks: add them to the queue.
   * Once the promise is resolve, the function _promise is replace.
   * @param {Function} onSuccess
   * @param {Function} onFail
   * @private
   */
  var _process = function (onSuccess, onFail) {
    _onSuccess.push(onSuccess);
    _onFail.push(onFail);
  };

  /**
   * Add an onSuccess callback and optionally an onFail callback to the Promise
   * @param {Function} onSuccess
   * @param {Function} [onFail]
   * @returns {Promise} promise
   */
  this.then = function (onSuccess, onFail) {
    return new Promise(function (resolve, reject) {
      var s = onSuccess ? _then(onSuccess, resolve, reject) : resolve;
      var f = onFail    ? _then(onFail,    resolve, reject) : reject;

      _process(s, f);
    }, me);
  };

  /**
   * Resolve the promise
   * @param {*} result
   * @type {Function}
   */
  var _resolve = function (result) {
    // update status
    me.resolved = true;
    me.rejected = false;
    me.pending = false;

    _onSuccess.forEach(function (fn) {
      fn(result);
    });

    _process = function (onSuccess, onFail) {
      onSuccess(result);
    };

    _resolve = _reject = function () { };

    return me;
  };

  /**
   * Reject the promise
   * @param {Error} error
   * @type {Function}
   */
  var _reject = function (error) {
    // update status
    me.resolved = false;
    me.rejected = true;
    me.pending = false;

    _onFail.forEach(function (fn) {
      fn(error);
    });

    _process = function (onSuccess, onFail) {
      onFail(error);
    };

    _resolve = _reject = function () { }

    return me;
  };

  /**
   * Cancel te promise. This will reject the promise with a CancellationError
   * @returns {Promise} self
   */
  this.cancel = function () {
    if (parent) {
      parent.cancel();
    }
    else {
      _reject(new CancellationError());
    }

    return me;
  };

  /**
   * Set a timeout for the promise. If the promise is not resolved within
   * the time, the promise will be cancelled and a TimeoutError is thrown.
   * If the promise is resolved in time, the timeout is removed.
   * @param {number} delay     Delay in milliseconds
   * @returns {Promise} self
   */
  this.timeout = function (delay) {
    if (parent) {
      parent.timeout(delay);
    }
    else {
      var timer = setTimeout(function () {
        _reject(new TimeoutError('Promise timed out after ' + delay + ' ms'));
      }, delay);

      me.always(function () {
        clearTimeout(timer);
      });
    }

    return me;
  };

  // attach handler passing the resolve and reject functions
  handler(function (result) {
    _resolve(result);
  }, function (error) {
    _reject(error);
  });
}
1323920
function doAfterAllPromises (params) {

          // Desctructuring:
          var $ul = params.$ul;
          var $promises = params.$promises;
          var level = params.level;
          var event = params.event;
          var leftOriented = String(params.orientation).toLowerCase() === 'left';

          $q.all($promises).then(function () {
            var topCoordinate  = event.pageY;
            var menuHeight = angular.element($ul[0]).prop('offsetHeight');
            var winHeight = $window.pageYOffset + event.view.innerHeight;

            /// the 20 pixels in second condition are considering the browser status bar that sometimes overrides the element
            if (topCoordinate > menuHeight && winHeight - topCoordinate < menuHeight + 20) {
              topCoordinate = event.pageY - menuHeight;
              /// If the element is a nested menu, adds the height of the parent li to the topCoordinate to align with the parent
              if(level && level > 0) {
                topCoordinate += event.event.currentTarget.offsetHeight;
              }
            } else if(winHeight <= menuHeight) {
              // If it really can't fit, reset the height of the menu to one that will fit
              angular.element($ul[0]).css({ 'height': winHeight - 5, 'overflow-y': 'scroll' });
              // ...then set the topCoordinate height to 0 so the menu starts from the top
              topCoordinate = 0;
            } else if(winHeight - topCoordinate < menuHeight) {
              var reduceThresholdY = 5;
              if(topCoordinate < reduceThresholdY) {
                reduceThresholdY = topCoordinate;
              }
              topCoordinate = winHeight - menuHeight - reduceThresholdY;
            }

            var leftCoordinate = event.pageX;
            var menuWidth = angular.element($ul[0]).prop('offsetWidth');
            var winWidth = event.view.innerWidth + window.pageXOffset;
            var padding = 5;

            if (leftOriented) {
              if (winWidth - leftCoordinate > menuWidth && leftCoordinate < menuWidth + padding) {
                leftCoordinate = padding;
              } else if (leftCoordinate < menuWidth) {
                var reduceThresholdX = 5;
                if (winWidth - leftCoordinate < reduceThresholdX + padding) {
                  reduceThresholdX = winWidth - leftCoordinate + padding;
                }
                leftCoordinate = menuWidth + reduceThresholdX + padding;
              } else {
                leftCoordinate = leftCoordinate - menuWidth;
              }
            } else {
              if (leftCoordinate > menuWidth && winWidth - leftCoordinate - padding < menuWidth) {
                leftCoordinate = winWidth - menuWidth - padding;
              } else if(winWidth - leftCoordinate < menuWidth) {
                var reduceThresholdX = 5;
                if(leftCoordinate < reduceThresholdX + padding) {
                  reduceThresholdX = leftCoordinate + padding;
                }
                leftCoordinate = winWidth - menuWidth - reduceThresholdX - padding;
              }
            }

            $ul.css({
              display: 'block',
              position: 'absolute',
              left: leftCoordinate + 'px',
              top: topCoordinate + 'px'
            });
          });

        }
75512
function wrapParsePromise(promise, parsePromise) {
      ['_rejected', '_rejectedCallbacks', '_resolved', '_resolvedCallbacks', '_result', 'reject', 'resolve']
        .forEach(function (prop) {
          promise[prop] = parsePromise[prop];
        });

      ['_continueWith', '_thenRunCallbacks', 'always', 'done', 'fail'].forEach(function (method) {
        promise[method] = wrap(parsePromise[method]);
      });

      ['then', 'catch'].forEach(function (method) {
        var func = promise[method];
        promise[method] = function wrappedAngularPromise() {
          var args = Array.prototype.slice.call(arguments, 0);
          var promise = func.apply(this, args);
          wrapParsePromise(promise, parsePromise);
          return promise;
        };
      });

      return promise;
    }
1219571
function promiseSequence(promiseFactories) {
    return __awaiter(this, void 0, void 0, function* () {
        const ret = [];
        for (const f of promiseFactories) {
            ret.push(yield f());
        }
        return ret;
    });
}
670093
function eventuallyEqual(promise, expected, done) {
    all([
        promise.should.be.fulfilled,
        promise.should.eventually.deep.equal(expected)
    ], done);
}
232090
function promisify() {
    var promiseLike = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;

    if (promiseLike instanceof _es6Promise.Promise) {
        return promiseLike;
    }

    if (typeof promiseLike === "function") {
        return promisify(promiseLike());
    }

    return new _es6Promise.Promise(function (resolve, reject) {
        promiseLike === false ? reject() : resolve(promiseLike);
    });
}
864561
function(result) {
      if (this._resolved || this._rejected) {
        throw "A promise was resolved even though it had already been " +
          (this._resolved ? "resolved" : "rejected") + ".";
      }
      this._resolved = true;
      this._result = arguments;
      var results = arguments;
      Parse._arrayEach(this._resolvedCallbacks, function(resolvedCallback) {
        resolvedCallback.apply(this, results);
      });
      this._resolvedCallbacks = [];
      this._rejectedCallbacks = [];
    }
45683
function Request__chain(promise, next) {

        if (!promise) {
            return new Promise(function (resolve, reject) {
                try {
                    resolve(next.apply(next, arguments));
                } catch (e) {
                    reject(new error.HttpError(500, {}, "Error on executing action", e));
                }
            });
        }

        return promise.then(function (data) {
            if (!!this.isPromiseChainStopped) {
                return promise;
            }
            return _handler(data);
        }.bind(this), this._handleError.bind(this));

        function _handler() {
            try {
                return next.apply(next, arguments);
            } catch (e) {
                throw new error.HttpError(500, {}, "Error on executing action", e);
            }
        }
    }
651626
function run_promises(promise_runner_stack,
		      accumulator_function, final_function, error_function){
    if( ! us.isEmpty(promise_runner_stack) ){
	var promise_runner = promise_runner_stack.shift();
	promise_runner().then(function(resp){
	    accumulator_function(resp);
	    run_promises(promise_runner_stack,
			 accumulator_function, final_function, error_function);
	}).fail(function(err){
	    if(err){
		error_function(err);
	    }
	}).done();
    }else{
	final_function();
    }
}
918907
function all (promises) {

    var done      = new promise.Promise,
        successes = [],
        failures  = [],
        failed    = false,
        completed = 0,
        total     = promises.length;

    if (promises.length === 0) {
        done.resolve([]);
        return done;
    }

    var check = function () {
        if (++completed < total) {
            return;
        }
        if (failures.length) {
            failures.successes = successes;
            done.reject(failures);
        }
        else {
            done.resolve(successes);
        }
    };

    for (var i = 0; i < total; i++) {
        promise.when(promises[i], function (result) {
            successes[i] = result;
            check();
        }, function (error) {
            failures[i] = error;
            check();
        });
    }

    return done;
}
825425
function promisePrompt(questions) {
    return new Promise(function(resolve, reject) {
        inquirer.prompt(questions, function(results) {
            resolve(results);
        });
    });
}