Resolver function to chain Promise to resolve results or reject errors. Used in postQuery.
@private
@param  {JSON} obj Returned from the neo4j server.
@return {Promise}     That resolves results or rejects errors.
321802
function resolver(obj) {
  return new Promise(function(resolve, reject) {
    _.isEmpty(obj.results) ? reject(new Error(JSON.stringify(obj.errors))) : resolve(obj.results);
  })
}
633234
function create_promise() {
  return new Promise((resolve, reject) => {
    this.request.end((err, response) => {
      if (err) {
        reject(handle_error.call(this, err, response))
      }else{
        if(successCb){
          successCb(response);
        }
      }

      if (this.is_json_response && this.method != 'del' && response.text !== '') {
        try {
          var parsed = JSON.parse(response.text)
        } catch(parse_err) {
          throw new Error(`NS1 API Response couldn't parse as JSON: ${parse_err}`)
        }
      } else {
        // TODO: Determine if there's a need to filter/reject empty response bodies on 200's
      }
      return resolve(parsed || true)
    })
  })
}
739788
function resolveObject(arg) {
  var resolvedObject = {};
  return Object.keys(arg)
      .reduce(function(soFar, key) {
        return soFar
            .then(resolveItem.bind(null, arg[key]))
            .then(function(value) {
              resolvedObject[key] = value;
            });
      }, Promise.resolve())
      .then(function() {
        return resolvedObject;
      });
}
555786
function createMongoosePromise(resolver) {
    var promise

    // mongoose 5 and up
    if (parseInt(mongoose.version) >= 5) {
      promise = new mongoose.Promise(resolver)
    }
    // mongoose 4.1 and up
    else if (mongoose.Promise.ES6) {
      promise = new mongoose.Promise.ES6(resolver)
    }
    // backward compatibility
    else {
      promise = new mongoose.Promise
      resolver(promise.resolve.bind(promise, null), promise.reject.bind(promise))
    }

    return 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;
            }
1206205
function(chain) {
      var method = status > 0 ? "resolve" :
                   status < 0 ? "reject" :
                   null;
      if (method) for (var i in chain) {
        chain[i][method](result);
      }
    }
1009928
function then(resolver, onFulfilled, onRejected) {
        var res = new Resolver();
        var promise = createPromise(res);

        if (isFunction(onFulfilled)) {
            onFulfilled = wrapCallback(res, promise, onFulfilled);
        }
        else {
            // not function
            // 'return promise' must fulfill with the same value
            // when 'main promise' is resolved
            // see #2.2.7.3
            onFulfilled = function (data) {
                res.fulfill(data);
            };
        }
        addListener(resolver, STATUS.FULFILLED, onFulfilled);

        if (isFunction(onRejected)) {
            onRejected = wrapCallback(res, promise, onRejected);
        }
        else {
            // not function
            // 'return promise' must reject with the same reason
            // when 'main promise' is rejected
            // see #2.2.7.4
            onRejected = function (reason) {
                res.reject(reason);
            };
        }
        addListener(resolver, STATUS.REJECTED, onRejected);

        return promise;
    }
469273
function resolve(promise) {
    var method = promise.state === FULFILLED ? 'onFulfilled' : 'onRejected';
    var arg = method === 'onFulfilled' ? promise.value : promise.reason;
    var handler, value;

    nextTick(function() {
      var isPromise;

      while (promise.handlers[0]) {
        handler = promise.handlers.shift();

        try {
          value = handler[method](arg);

          // Handle "thenables" as well as Promises
          isPromise = value instanceof Promise || value && isFunc(value.then);

          if (isPromise) {
            value.then(function(value) { fulfill(handler.promise, value); },
                       function(reason) { reject(handler.promise, reason); });
          } else {
            fulfill(handler.promise, value);
          }
        } catch(err) {
          reject(handler.promise, err);
        }
      }
    });

    return promise;
  }
120478
function( type, obj ) {
		var tmp,
			count = 1,
			defer = jQuery.Deferred(),
			elements = this,
			i = this.length,
			resolve = function() {
				if ( !( --count ) ) {
					defer.resolveWith( elements, [ elements ] );
				}
			};

		if ( typeof type !== "string" ) {
			obj = type;
			type = undefined;
		}
		type = type || "fx";

		while ( i-- ) {
			tmp = dataPriv.get( elements[ i ], type + "queueHooks" );
			if ( tmp && tmp.empty ) {
				count++;
				tmp.empty.add( resolve );
			}
		}
		resolve();
		return defer.promise( obj );
	}
360534
function finishBasicPromise (resolve, reject) {
  return (err, res) => {
    if (err) {
      return reject(err);
    } else {
      return resolve(res);
    }
  };
}
306154
function (callback) {
        return new Promise((resolve, reject) => {
          this.end(result => {
            try {
              resolve(callback(result))
            } catch (err) {
              reject(err)
            }
          })
        })
      }
1112904
function promiseResult (options, data) {
		log(`promiseResult: data ${data}`);
		return new Promise((resolve, reject) => {
			/* Check cache to avoid I/O. */
			const cacheHit = checkCache(config, pattern);
			if (cacheHit !== RESPONSE_UNKNOWN) {
				log(`Cache hit: ${cacheHit}`);
				return resolve(cacheHit);
			}

			const req = https.request(options, (res) => {
				res.setEncoding('utf8');

				let response = '';
				res.on('data', (chunk) => {
					log(`Got data`);
					response += chunk;
				});

				res.on('end', () => {
					log(`end: I got ${JSON.stringify(response)}`);

					const result = serverResponseToRESPONSE(response);
					log(`end: result ${result}`);
					updateCache(config, postObject.pattern, result);

					if (result === RESPONSE_INVALID) {
						return reject(result);
					} else {
						return resolve(result);
					}
				});
			});

			req.on('error', (e) => {
				log(`Error: ${e}`);
				return reject(RESPONSE_INVALID);
			});

			// Write data to request body.
			log(`Writing to req:\n${data}`);
			req.write(data);
			req.end();
		});
	}
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]));
	});
}
585614
function() {
		var that = this;
		return new Promise(function(resolve, reject) {
			that.resolve(function(err, val) {
				if (err) {
					reject(err);
				} else {
					resolve(val);
				}
			});
		});
	}
508170
function (web3Provider, result) {
    return new Promise(function (onResolve, onReject) {
      onResolve(web3Provider.eth.abi.decodeParameter('address', result));
    });
  }
46189
function Promise(fn) {
  if (typeof this !== 'object') {
    throw new TypeError('Promises must be constructed via new');
  }
  if (typeof fn !== 'function') {
    throw new TypeError('not a function');
  }
  this._37 = 0;
  this._12 = null;
  this._59 = [];
  if (fn === noop) return;
  doResolve(fn, this);
}
290316
function(err, res) {
    if (_.isFunction(callback)) {
      try {
        res = callback(err, res);
        err = null;
      } catch(e) {
        err = e;
      }
    }
    if (err) {
      deferred.reject(err);
    } else {
      deferred.resolve(res);
    }
  }