returns a Promise
4406
function installPluginsFromConfigXML(args) {
    events.emit('verbose', 'Checking config.xml for saved plugins that haven\'t been added to the project');

    //Install plugins that are listed on config.xml
    var projectRoot = cordova_util.cdProjectRoot();
    var configPath = cordova_util.projectConfig(projectRoot);
    var cfg = new ConfigParser(configPath);
    var plugins_dir = path.join(projectRoot, 'plugins');

    // Get all configured plugins
    var plugins = cfg.getPluginIdList();
    if (0 === plugins.length) {
        return Q('No plugins found in config.xml that haven\'t been added to the project');
    }


    // Intermediate variable to store current installing plugin name
    // to be able to create informative warning on plugin failure
    var pluginName;

    // CB-9560 : Run `plugin add` serially, one plugin after another
    // We need to wait for the plugin and its dependencies to be installed
    // before installing the next root plugin otherwise we can have common
    // plugin dependencies installed twice which throws a nasty error.
    return promiseutil.Q_chainmap_graceful(plugins, function(featureId) {
        var pluginPath = path.join(plugins_dir, featureId);
        if (fs.existsSync(pluginPath)) {
            // Plugin already exists
            return Q();
        }
        events.emit('log', 'Discovered plugin "' + featureId + '" in config.xml. Adding it to the project');
        var pluginEntry = cfg.getPlugin(featureId);

        // Install from given URL if defined or using a plugin id. If spec isn't a valid version or version range,
        // assume it is the location to install from.
        var pluginSpec = pluginEntry.spec;
        pluginName = pluginEntry.name;

        // CB-10761 If plugin spec is not specified, use plugin name
        var installFrom = pluginSpec || pluginName;
        if (pluginSpec && semver.validRange(pluginSpec, true))
            installFrom = pluginName + '@' + pluginSpec;

        // Add feature preferences as CLI variables if have any
        var options = {
            cli_variables: pluginEntry.variables,
            searchpath: args.searchpath,
            fetch: args.fetch || false,
            save: args.save || false
        };
        var plugin = require('./plugin');
        return plugin('add', installFrom, options);
    }, function (error) {
        // CB-10921 emit a warning in case of error
        var msg = 'Failed to restore plugin \"' + pluginName + '\" from config.xml. ' +
            'You might need to try adding it again. Error: ' + error;
        events.emit('warn', msg);
    });
}
368199
function rimrafPromise(dir) {
  return new Promise((resolve, reject) => {
    rimraf(dir, err => {
      if (err) {
        reject(err);
      } else {
        resolve();
      }
    });
  });
}
209656
function getAPIJSONPromise(oChainObject) {
		return new Promise(function(oResolve, oReject) {
			fs.readFile(sInputFile, 'utf8', (oError, sFileData) => {
				if (oError) {
					oReject(oError);
				} else {
					oChainObject.fileData = JSON.parse(sFileData);
					oResolve(oChainObject);
				}
			});
		});
	}
841514
function(arr, iterator) {
			return Promise.map.call(this, arr, function(item, index, value) {
				return iterator.call(this, item, index, value);
			}.bind(this)).return(arr);
		}
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);
        });
    }
564522
function reversePromises (promises) {
    return promises.map(function (promise) {
      var d = $q.defer();
      promise.then(d.reject, d.resolve);
      return d.promise;
    });
  }
527945
public function promise(): Promise
    {
        return new class($this) implements Promise {

            private $defer;

            public function __construct(Deferred $defer)
            {
                $this->defer = $defer;
            }

            /**
             * {@inheritdoc}
             */
            public function when(callable $callback): void
            {
                if ($this->defer->state & AbstractPromise::SUCCEEDED) {
                    try {
                        $callback(null, $this->defer->result);
                    } catch (\Throwable $e) {
                        $this->defer->context->handleError($e);
                    }
                } elseif ($this->defer->state & AbstractPromise::FAILED) {
                    try {
                        $callback($this->defer->result);
                    } catch (\Throwable $e) {
                        $this->defer->context->handleError($e);
                    }
                } elseif ($this->defer->result) {
                    if (\is_array($this->defer->result) && isset($this->defer->result[0])) {
                        $this->defer->result[] = $callback;
                    } else {
                        $this->defer->result = [
                            $this->defer->result,
                            $callback
                        ];
                    }
                } else {
                    $this->defer->result = $callback;
                }
            }
        };
    }
1100852
function wait(ms = 0) {
  return function(val) {
    return new Promise(resolve => setTimeout(_ => resolve(val), ms));
  };
}
720383
function(){
        var deferred = Q.defer();

        fs.readFile( this.path, "utf-8", function( err, data ){
            if( err ){
                deferred.reject( err );
                return;
            }
            this.srcHTMLCode = data;
            deferred.resolve( this );
        }.bind( this ) );

        return deferred.promise;
    }
124974
function wrapFunctionToReturnPromise(fn, Promise) {
	return function() {
		try {
			const result = fn.apply(this, arguments);
			if (result instanceof Promise) return result;
			return Promise.resolve(result);
		} catch (err) {
			return new Promise((resolve, reject) => { // jshint ignore:line
				reject(err);
			});
		}
	};
}
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);
  });
}
150862
function Promise(cb, ctx) {
  this.context = ctx;
  this.thenChain = [];
  this.errCb = null;
  this.noErrorCb = null;
  process.nextTick(function() {
    cb();
  });
}
1118486
async function () {

    const oThis = this
      , statusResponse = {chain: {value: false, utility: false}};

    // check geth status
    for (var chainName in statusResponse.chain) {
      var response = await oThis._gethStatus(chainName);
      if (response.isSuccess()) {
        statusResponse.chain[chainName] = true;
      } else {
        return Promise.resolve(response);
      }
    }

    return Promise.resolve(responseHelper.successWithData(statusResponse));

  }
670934
@NotNull
	public static Promise<Void> all(@NotNull Iterator<? extends Promise<?>> promises) {
		if (!promises.hasNext()) return all();
		@NotNull PromiseAll<Object> resultPromise = new PromiseAll<>();
		while (promises.hasNext()) {
			Promise<?> promise = promises.next();
			if (promise.isResult()) continue;
			if (promise.isException()) return Promise.ofException(promise.materialize().getException());
			resultPromise.countdown++;
			promise.next(resultPromise);
		}
		return resultPromise.countdown != 0 ? resultPromise : Promise.complete();
	}
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();
}
1194540
function resolve(x) {
			return isPromise(x) ? x
				: new Promise(Handler, new Async(getHandler(x)));
		}
855426
function asPromise (val) {
	if (val && typeof val.then === 'function') {
		return val;
	}
	var deferred = new PromiseFactory();
	deferred.resolve(val);
	return deferred.promise();
}