Run async validator

@param {function} passes
@param {function} fails
@return {void}
774377
function (passes, fails) {
    var _this = this;
    passes = passes || function () {};
    fails = fails || function () {};

    var failsOne = function (rule, message) {
      _this._addFailure(rule, message);
    };

    var resolvedAll = function (allPassed) {
      if (allPassed) {
        passes();
      } else {
        fails();
      }
    };

    var asyncResolvers = new AsyncResolvers(failsOne, resolvedAll);

    var validateRule = function (inputValue, ruleOptions, attribute, rule) {
      return function () {
        var resolverIndex = asyncResolvers.add(rule);
        rule.validate(inputValue, ruleOptions.value, attribute, function () {
          asyncResolvers.resolve(resolverIndex);
        });
      };
    };

    for (var attribute in this.rules) {
      var attributeRules = this.rules[attribute];
      var inputValue = this._objectPath(this.input, attribute);

      if (this._hasRule(attribute, ['sometimes']) && !this._suppliedWithData(attribute)) {
        continue;
      }

      for (var i = 0, len = attributeRules.length, rule, ruleOptions; i < len; i++) {
        ruleOptions = attributeRules[i];

        rule = this.getRule(ruleOptions.name);

        if (!this._isValidatable(rule, inputValue)) {
          continue;
        }

        validateRule(inputValue, ruleOptions, attribute, rule)();
      }
    }

    asyncResolvers.enableFiring();
    asyncResolvers.fire();
  }
852359
async function () {
    const oThis = this
    ;

    try {

      const bigBalance = await oThis._getStakerSTBalance();

      var approveRsp = await oThis._approve(bigBalance);
      approveRsp.transaction_uuid = uuid.v4();

      return Promise.resolve(approveRsp);

    } catch (err) {
      let errObj = responseHelper.error({
        internal_error_identifier: 's_sam_aovc_1',
        api_error_identifier: 'something_went_wrong',
        error_config: basicHelper.fetchErrorConfig()
      });

      return Promise.resolve(errObj);
    }
  }
117483
function validator(value, next) {
    validationErrors = [];
    var isValid = true;

    validatorsArray.forEach(function(validator) {
      validator.validator.call(this, value, function(valid) {
        if (!valid) {
          // Append message
          validationErrors.push(validator.message);

          isValid = false;
        }
      });
    }.bind(this));
    return next(isValid);
  }
700077
function makeValidator(spec) {
  const props = 'header query params body'.split(' ');

  return async function validator(ctx, next) {
    if (!spec.validate) return await next();

    let err;

    for (let i = 0; i < props.length; ++i) {
      const prop = props[i];

      if (spec.validate[prop]) {
        err = validateInput(prop, ctx, spec.validate);

        if (err) {
          captureError(ctx, prop, err);
          if (!spec.validate.continueOnError) return ctx.throw(err);
        }
      }
    }

    await next();

    if (spec.validate._outputValidator) {
      debug('validating output');

      err = spec.validate._outputValidator.validate(ctx);
      if (err) {
        err.status = 500;
        return ctx.throw(err);
      }
    }
  };
}
82239
function (fn, repeatTest = 0, args = []) {
    let result, error

    /**
     * if a new hook gets executed we can assume that all commands should have finised
     * with exception of timeouts where `commandIsRunning` will never be reset but here
     */
    // commandIsRunning = false

    try {
        result = fn.apply(this, args)
    } catch (e) {
        error = e
    }

    /**
     * handle errors that get thrown directly and are not cause by
     * rejected promises
     */
    if (error) {
        if (repeatTest) {
            return executeAsync(fn, --repeatTest, args)
        }
        return new Promise((resolve, reject) => reject(error))
    }

    /**
     * if we don't retry just return result
     */
    if (repeatTest === 0 || !result || typeof result.catch !== 'function') {
        return new Promise(resolve => resolve(result))
    }

    /**
     * handle promise response
     */
    return result.catch((e) => {
        if (repeatTest) {
            return executeAsync(fn, --repeatTest, args)
        }

        e.stack = e.stack.split('\n').filter(STACKTRACE_FILTER_FN).join('\n')
        return Promise.reject(e)
    })
}
1193454
async function run() {
  await benchmark(
    () => map(f => f(), createPromiseFuncs()),
    'Map (concurrency: 3)'
  );
  await benchmark(
    () => mapWithOptions(f => f(), { concurrency: 1 }, createPromiseFuncs()),
    'Map (concurrency: 1)'
  );
  await benchmark(
    () => mapSeries(f => f(), createPromiseFuncs()),
    'Map series'
  );
}
632786
function(cardNumber, success, error) {
    success = success || noop;
    error = error || noop;
    exec(success, error, "CordovaStripe", "validateCardNumber", [cardNumber]);
  }
1234384
function doAsyncBench(fn, callback) {

		var fnOverhead,
		    pretotal,
		    result,
		    args,
		    i;

		if (benchRunning > 0) {

			// Keep function optimized by not leaking the `arguments` object
			args = new Array(arguments.length);
			for (i = 0; i < args.length; i++) args[i] = arguments[i];

			benchQueue.push(args);
			return;
		}

		benchRunning++;

		// See how many times we can get it to run for 300ms
		Collection.Function.doTime(300, fn, function(err, runs, elapsed) {

			// See how the baseline latency is like
			Blast.getEventLatencyBaseline(function(err, median) {
				asyncTest(fn, runs, median+(getFunctionOverhead(runs)*8), function asyncDone(err, result) {

					var next,
					    name;

					// Call the callback
					if (callback) {
						result.name = fn.name || '';
						callback(err, result);
					} else {
						name = fn.name || '';
						if (name) name = 'for "' + name + '" ';

						console.log('Benchmark ' + name + 'did ' + Bound.Number.humanize(result.ops) + '/s (' + Bound.Number.humanize(result.iterations) + ' iterations)');
					}

					benchRunning--;

					// Schedule a next benchmark
					if (benchRunning == 0 && benchQueue.length > 0) {

						// Get the top of the queue
						next = benchQueue.shift();

						Blast.setImmediate(function() {
							doAsyncBench.apply(null, next);
						});
					}
				});
			});
		});
	}
1221196
function wrap_sync(fn) {
  return function (params) {
    var val = fn(params);
    if (val && !isPromise(val)) throw val;
    return val;
  };
}
1112430
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;
  }
1161307
function(url, success, fail) {
        success = success || noop;
        fail = fail || noop;

        //if there's a queue
        if (queue[url] instanceof Array) {
            //just add it
            return queue[url].push({
                success: success,
                fail: fail
            });
        }

        //otherwise there is not a queue
        //so let's create one
        queue[url] = [{
            success: success,
            fail: fail
        }];

        var xhr;

        if(typeof XMLHttpRequest !== 'undefined') {
            xhr = new XMLHttpRequest();
        } else {
            var versions = [
                'MSXML2.XmlHttp.5.0',
                'MSXML2.XmlHttp.4.0',
                'MSXML2.XmlHttp.3.0',
                'MSXML2.XmlHttp.2.0',
                'Microsoft.XmlHttp'];

             for(var i = 0; i < versions.length; i++) {
                try {
                    xhr = new ActiveXObject(versions[i]);
                    break;
                }
                catch(e){}
             }
        }

        if(!xhr) {
            //fail the queue
            queue[url].forEach(function(callback) {
                callback.fail(null);
            });

            delete queue[url];
            return;
        }

        var process = function() {
            if(xhr.readyState < 4) {
                return;
            }

            if(xhr.status >= 404 && xhr.status < 600) {
                //fail the queue
                queue[url].forEach(function(callback) {
                    callback.fail(xhr);
                });

                delete queue[url];
                return;
            }

            if(xhr.status !== 200) {
                return;
            }

            // all is well
            if(xhr.readyState === 4) {
                var response = xhr.responseText;

                try {
                    response = JSON.parse(response);
                } catch(e) {}

                //fail the queue
                queue[url].forEach(function(callback) {
                    callback.success(response, xhr);
                });

                delete queue[url];
            }
        };

        xhr.onreadystatechange = process;
        xhr.open('GET', url, true);
        xhr.send('');
    }
1118504
function fail (label, messages) {
  messages.showAnyWarnings('loading')
  messages.showErrors('loading')

  const oops = new Error(messages.errors.join('\n'))
  oops.errors = messages.errors
  throw oops
}
1284986
function asyncBatch (
  renderer,
  pushable,
  resolve,
  reject
) {
  const pull = pullBatch(renderer, pushable);

  pull.then(result => {
    if (result === EXHAUSTED) {
      resolve();
    } else {
      setImmediate(
        asyncBatch,
        renderer,
        pushable,
        resolve,
        reject,
      );
    }
  }).catch(err => {
    reject(err);
  });
}
500293
function async(value, bool) {
   var def = promise()
   setTimeout(function() {
 	   if(!bool) def.fulfill(value)
     else def.reject('error')
   }, 10)
   return def.promise
 }
90681
async function validate(descriptor) {
  const {valid, errors} = await Package.load(descriptor)
  return {valid, errors}
}
490054
function(error) {
		var that = this,
			param = this.chainParameter,
			stopPointer = {},
			utils = {
				stop: null,
				url: this.scraper.url,
				scraper: this,
				params: param,
				lastReturn: undefined
			},
			keep = true;
		this.chainParameter = null;

		if (error) {
			this.errorCallback(error, utils);
			this.doneCallback(utils);
			return;
		}

		async.eachSeries(this.promises, function dispatcher(fn, callback) {
			var done = function(err, lastReturn) {
				utils.lastReturn = lastReturn;
				if (err === stopPointer) {
					keep = false;
					callback(err);
				} else if (err) {
					callback(err);
				} else if (keep) {
					callback();
				}
			};
			utils.stop = function() {
				done(stopPointer, null);
			};

			try {
				fn.call(that, done, utils);
			} catch (err) {
				done(err, null);
			}
		}, function(err) {
			utils.stop = null;
			if (err && err !== stopPointer) {
				that.errorCallback(err, utils);
			}
			that.doneCallback(utils.lastReturn, utils);
			that.scraper.close();
		});
	}
930483
function onRequestError(error, result, endCallback) {
      result.currentRetries++;
      async.parallel([
        async.apply(recrawlError, error, result),
        async.apply(retrySameUrl,error, result)
      ],function(error){
          endCallback(error);
      });

  }