Create an already-rejected {@link Promise} with the supplied
rejection reason.
@private

@param {*} reason
@return {Promise} rejected promise
19680
function rejected(reason) {
            var p = new Promise();
            p.then = then;
            states.reject(p, reason);
            return p;

            function then(_, onRejected) {
                try {
                    return resolve(typeof onRejected == 'function' ? onRejected(reason) : rejected(reason));
                } catch (e) {
                    return rejected(e);
                }
            }
        }
736376
public <T> RPromise<T> deferredPromise () {
    return new RPromise<T>() {
      @Override public void succeed (final T value) {
        invokeLater(new Runnable() {
          public void run () { superSucceed(value); }
        });
      }
      @Override public void fail (final Throwable cause) {
        invokeLater(new Runnable() {
          public void run () { superFail(cause); }
        });
      }
      private void superSucceed (T value) { super.succeed(value); }
      private void superFail (Throwable cause) { super.fail(cause); }
    };
  }
324050
function createReadFilePromise () {
  return (filepath) => {
    return new Promise((resolve, reject) => {
      fs.readFile(filepath, 'utf8', function (error, data) {
        if (error) {
          reject(new Error(`Cannot read ${filepath}, got: ${error}`))
        } else if (!data) {
          reject(new Error(`No content at ${filepath}`))
        } else {
          resolve(data.split('\n'))
        }
      })
    })
  }
}
1306918
function promiseWhen(promise, fulfilled, rejected) {
        // simply call rejected
        if (promise instanceof Reject) {
            // if there is a rejected , should always has! see when()
            rejected.call(promise, promise[PROMISE_VALUE]);
        } else {
            var v = promise[PROMISE_VALUE], pendings = promise[PROMISE_PENDINGS];
            if (pendings === undefined) {
                pendings = promise[PROMISE_PENDINGS] = [];
            }    // unresolved
                 // pushed to pending list
            // unresolved
            // pushed to pending list
            if (pendings) {
                pendings.push([
                    fulfilled,
                    rejected
                ]);
            } else if (isPromise(v)) {
                // rejected or nested promise
                promiseWhen(v, fulfilled, rejected);
            } else {
                // fulfilled value
                // normal value represents ok
                // need return user's return value
                // if return promise then forward
                if (fulfilled) {
                    fulfilled.call(promise, v);
                }
            }
        }
    }
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)
    })
  })
}
1148945
function doResolve(promise, resolve, reject, value, context) {
  var _reject = reject;
  var then;
  var _resolve;
  try {
    if (value === promise) {
      throw new TypeError('Cannot fulfill promise with itself');
    }
    var isObj = isObject(value);
    if (isObj && value instanceof promise.constructor) {
      adopt(promise, value._state, value._value, value);
    } else if (isObj && (then = value.then) && isFunction(then)) {
      _resolve = function(value) {
        _resolve = _reject = noop;
        doResolve(promise, resolve, reject, value, value);
      };
      _reject = function(reason) {
        _resolve = _reject = noop;
        reject(reason);
      };
      then.call(
        context,
        function(value) { _resolve(value); },
        function(reason) { _reject(reason); }
      );
    } else {
      resolve(value);
    }
  } catch (e) {
    _reject(e);
  }
}
285230
function makeDeferred() {
  var resolvePromise = null;
  var rejectPromise = null;

  var promise = new Promise(function (resolve, reject) {
    resolvePromise = resolve;
    rejectPromise = reject;
  });

  return {
    promise: promise,
    resolve: resolvePromise,
    reject: rejectPromise
  };
}
253566
function (orig) {
      return function () {
        var args = Array.from(arguments);
        var promise = createPromise();

        orig.apply(undefined, args.concat(function (error, stdout, stderr) {
          if (error !== null) {
            error.stdout = stdout;
            error.stderr = stderr;
            promiseReject(promise, error);
          } else {
            promiseResolve(promise, { stdout: stdout, stderr: stderr });
          }
        }));

        return promise;
      };
    }
184297
function coerce(promise) {
        var deferred = defer();
        nextTick(function () {
            try {
                promise.then(deferred.resolve, deferred.reject, deferred.notify);
            } catch (exception) {
                deferred.reject(exception);
            }
        });
        return deferred.promise;
    }
1293763
@Contract(pure = true)
	@NotNull
	public static <T> Promise<T> timeout(@NotNull Promise<T> promise, long delay) {
		if (promise.isComplete()) return promise;
		if (delay <= 0) return Promise.ofException(TIMEOUT_EXCEPTION);
		return promise.next(new NextPromise<T, T>() {
			@Nullable ScheduledRunnable schedule = getCurrentEventloop()
					.delay(delay,
							() -> {
								schedule = null;
								tryCompleteExceptionally(TIMEOUT_EXCEPTION);
							});

			@Override
			public void accept(T result, @Nullable Throwable e) {
				if (schedule != null) {
					schedule.cancel();
					schedule = null;
				}
				if (e == null) {
					tryComplete(result);
				} else {
					tryCompleteExceptionally(e);
				}
			}
		});
	}
1026911
function (requestPromise) {
  var that = this;

  // this will be bound to Client instance later in the Client constructor
  if (!this.isValid) {
    return Promise.reject(new Model({Errors: this.errors.join(',')}));
  }

  return requestPromise.apply(null, slice.call(arguments, 1))
    .then(function (response) {
      return new Model(response);
    }, function (reason) {
      var errors = that.errors;
      if (reason.statusCode >= 400 && reason.statusCode < 500) {
        errors.push(ClientError.HTTP_CLIENT_ERROR);
      } else if (reason.statusCode >= 500 && reason.statusCode < 600) {
        errors.push(ClientError.HTTP_SERVER_ERROR);
      } else {
        errors.push(ClientError.EXCEPTION);
      }
      return Promise.reject(new Model({Errors: errors.join(',')}));
    });
}
1142602
function promiseMiddleware (request, response, middleware) {
  return new promiseMiddleware.Promise(function (resolve, reject) {
    middleware(request, response, function next (error) {
      return error ? reject(error) : resolve()
    })
  })
}
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);
}
1307100
def reject(self, reason=None, **kwargs):
        
        return self.nest(Reject(reason=reason, **kwargs))
1368197
function generate(argv, config) {
  return new Promise((resolve, reject) => {
    _generate(argv, config, resolve, reject);
  });
}
685422
function tryFn(fn, args) {
  try {
    return Promise.resolve(fn.apply(null, args));
  } catch (e) {
    return Promise.reject(e);
  }
}
195838
function withPromise(callback, {raf = false} = {}) {
  return new Promise((resolve, reject) => {
    if (raf) {
      requestAnimationFrame(() => {
        callback(resolve, reject);
      });
    } else {
      callback(resolve, reject);
    }
  });
}