Creates a Promise.
@param {Object} f Function.
@param {Array} args List of arguments.
@returns {Promise} Promise.
194065
function async(f, args) {
    return new Promise(
      function(resolve, reject) {
        try {
          var r = f.apply(undefined, args);
          resolve(r);
        } catch(e) {
          reject(e);
        }
      }
    );
  }
685422
function tryFn(fn, args) {
  try {
    return Promise.resolve(fn.apply(null, args));
  } catch (e) {
    return Promise.reject(e);
  }
}
767832
function awaitFunctionCall() {
                let func;
                const promise = new Promise((resolve, reject) => {
                    func = function(...args) {
                        resolve(args);
                        return new Promise((resolve, reject) => {
                            // give us some time to process the result before
                            // continuing
                            global.setTimeout(resolve, 1);
                        });
                    };
                });
                return {func, promise};
            }
1236460
function (args, result, func, extra) {
		return new SR.promise(function (resolve, reject) {
			UTIL.safeCall(func, args, result, function () {
				UTIL.safeCall(resolve);
			}, extra);
		});
	}
791111
public final Object f(Object... args) {
    return dfd != null &&
        (cache == CacheType.ALL ||
            cache == CacheType.RESOLVED && dfd.promise().isResolved() ||
        cache == CacheType.REJECTED && dfd.promise().isRejected())
        ? dfd.promise()
        : new PromiseFunction() {
          public void f(Deferred dfd) {
            FunctionDeferred.this.resolve = resolve;
            FunctionDeferred.this.reject = reject;
            FunctionDeferred.this.dfd = dfd;
            FunctionDeferred.this.f(dfd);
          }
        };
  }
438547
function _apply(func, thisArg, promisedArgs) {
		return well.all(promisedArgs || []).then(function(args) {
			return func.apply(thisArg, args);
		});
	}
855426
function asPromise (val) {
	if (val && typeof val.then === 'function') {
		return val;
	}
	var deferred = new PromiseFactory();
	deferred.resolve(val);
	return deferred.promise();
}
472760
function (promise){
    		promise.success = function (fn) {
	            promise.then(fn);
	            return promise;
	        };

	        promise.error = function (fn) {
	            promise.then(null, fn);
	            return promise;
	        };
    	}
784205
function(args) {
    var baseUrl = this.baseUrl + this.basePath;
    var authToken = this.authToken;
    var qs = this._buildQueryString(args.params);

    return new Promise(function(resolve, reject) {
      var req = new XMLHttpRequest();

      req.onreadystatechange = function() {
        if (req.readyState === 4) {
          try {
            var response = JSON.parse(req.responseText);
            var status = req.status;

            if (status >= 200 && status < 400) {
              return resolve(
                addShadowProperty({
                  target: response,
                  property: 'httpRequest',
                  value: req
                })
              );
            }

            return reject(
              createApiError(
                merge(response, {
                  status: status,
                  httpRequest: req
                })
              )
            );
          } catch (err) {
            reject(err);
          }
        }
      };

      req.open(args.method, baseUrl + args.path + qs, true);
      req.setRequestHeader('Authorization', 'Bearer ' + authToken);
      req.setRequestHeader('Accept', 'application/json');
      req.setRequestHeader('Content-type', 'application/json; charset=utf-8');
      req.send(args.payload ? JSON.stringify(args.payload) : null);
    });
  }
656879
function (promise, i) {
            var self = this;
            promise.then(
                function () {
                    var args = argsToArray(arguments);
                    args.unshift(i);
                    spreadArgs(self.callback, args, self);
                    promise = i = self = null;
                },
                function () {
                    var args = argsToArray(arguments);
                    args.unshift(i);
                    spreadArgs(self.errback, args, self);
                    promise = i = self = null;
                });
        }
668146
function promisify(f, args) {
  return new Promise((resolve, reject) => f.apply(this, args.concat((err, x) => err ? reject(err) : resolve(x))));
}
1122638
public final Promise set(String key, byte[] value, SetArgs args) {
		byte[] binaryKey = key.getBytes(StandardCharsets.UTF_8);
		if (client != null) {
			if (args == null) {
				return new Promise(client.set(binaryKey, value));
			}
			return new Promise(client.set(binaryKey, value, args));
		}
		if (clusteredClient != null) {
			if (args == null) {
				return new Promise(clusteredClient.set(binaryKey, value));
			}
			return new Promise(clusteredClient.set(binaryKey, value, args));
		}
		return Promise.resolve();
	}
1119219
function (fn) {
    var origError = console.error
    var origExit = process.exit
    var origLog = console.log

    console.error = error = jest.fn()
    console.log = print = jest.fn()
    process.exit = exit = jest.fn()

    return execPromise(fn).then(
      function (value) {
        console.error = origError
        console.log = origLog
        process.exit = origExit

        return value
      },
      function (reason) {
        console.error = origError
        console.log = origLog
        process.exit = origExit

        throw reason
      }
    )
  }
1330346
function promisify(func) {
  return function promisified() {
    var args = Array.prototype.slice.call(arguments);
    var context = this;

    return new Promise(function(resolve, reject) {
      try {
        func.apply(context, args.concat(function(err, data) {
          if (err) {
            return reject(err);
          }

          resolve(data);
        }));
      } catch(err) {
        reject(err);
      }
    });
  };
}
91056
function promisedRequest(params, callback) {
  var deferred = Promise.defer();
  var req;
  var createRequest = function() {
    if (!req) {
      req = request(params, function(err, response) {
        if (err) {
          deferred.reject(err);
        } else {
          deferred.resolve(response);
        }
      });
    }
    return req;
  };
  return streamify(deferred.promise, createRequest).thenCall(callback);
}
450812
function utilCallbackAfterPromise(self, func, args, cb) {
	args = Array.prototype.slice.apply(args);
	let lastarg = args.pop();
	if(!cb) cb = lastarg;
	func.apply(self, args).then(res => {
		try {
			cb(null, res);
		} catch(e) {
			process.nextTick(() => { throw e });
		}
	}).catch((err) => {
		try {
			cb(err);
		} catch(e) {
			process.nextTick(() => { throw e });
		}
	});
}
815555
function (func) {
		if (!(this instanceof Deferred)) {
			return new Deferred();
		}
		this._doneFuncs = [];
		this._failFuncs = [];
		this._resultArgs = null;
		this._status = '';
		// Check for option `function` -- call it with this as context and as first
		// parameter, as specified in jQuery API.
		if (func) {
			func.call(this, this);
		}
	}