/* call as promise
493467
function pCall(fn) {
	try {
		var args = Array.prototype.slice.call(arguments, 1)
		var val = fn.apply(null, args);
		return asPromise(val);
	} catch (e) {
		return asRejectedPromise(e);
	}
}
367587
function(javascript) {
    try {
      return Promise.resolve({
        input: javascript,
        output: eval(javascript),
        exception: null
      });
    }
    catch (ex) {
      return Promise.resolve({
        input: javascript,
        output: null,
        exception: ex
      });
    }
  }
676609
function promiseTry(callback) {
  try {
    const maybePromise = callback();

    if (isPromise(maybePromise)) {
      return maybePromise;
    } else {
      return Promise.resolve(maybePromise);
    }
  } catch (err) {
    return Promise.reject(err);
  }
}
237212
function makePromise(fn) {
	return function() {
		var args = Array.prototype.slice.call(arguments);
		if (hasCallback(args)) {
			// argument list has callback, so call method with callback
			return callCallback(fn, args);
		} else {
			// no callback, call method with promises
			return callPromise(fn, args);
		}
	}
}
1297280
function() {
        return new Promise(function(resolve, reject) {
            try {
                let files;
                if(fileUtils.fileExists(resourceDir)) {
                    files = fs.readdirSync(resourceDir);
                    files = _.uniqBy(files, function (f) {
                        return path.basename(f, '.' + rc.tools.spec.file_ext);
                    }).map(function(f) { return path.join(resourceDir, f);});
                }
                if(!files) files = [];
                resolve(files);
            } catch (err) {
                reject(err);
            }
        }).then(function(files) {
            return promiseUtils.chain(rc.tools.inspect, function(err) {
                console.error(err);
                return false;
            })(files);
        });
    }
244944
function (callback) {
            var promise = new Promise();
            this.addCallback(function () {
                try {
                    when(isFunction(callback) ? callback.apply(this, arguments) : callback).then(promise);
                } catch (e) {
                    promise.errback(e);
                }
            });

            this.addErrback(function () {
                try {
                    when(isFunction(callback) ? callback.apply(this, arguments) : callback).then(promise);
                } catch (e) {
                    promise.errback(e);
                }
            });
            return promise.promise();
        }
1252583
function promisedConcat(promises, unknown) {
    return promises.then(function(values) {
      return Promise.resolve(unknown).then(function(value) {
        return values.concat([ value ]);
      });
    });
  }
168986
function isPromiseRejectCall(node) {
            return node.callee.type === "MemberExpression" &&
                node.callee.object.type === "Identifier" && node.callee.object.name === "Promise" &&
                node.callee.property.type === "Identifier" && node.callee.property.name === "reject";
        }
1253098
function checkPromise(index) {
      var res = cb(callbacks[index]); // actually calling callback
      if (res instanceof Promise) {
        res.then(function (cbRes) {
          if (cbRes !== false) {
            // keep going
            if (index > 0) {
              checkPromise(index - 1);
            }
          }
        });
      } else {
        if (res !== false) {
          // keep going
          if (index > 0) {
            checkPromise(index - 1);
          }
        }
      }
    }
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);
}
232090
function promisify() {
    var promiseLike = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;

    if (promiseLike instanceof _es6Promise.Promise) {
        return promiseLike;
    }

    if (typeof promiseLike === "function") {
        return promisify(promiseLike());
    }

    return new _es6Promise.Promise(function (resolve, reject) {
        promiseLike === false ? reject() : resolve(promiseLike);
    });
}
195838
function withPromise(callback, {raf = false} = {}) {
  return new Promise((resolve, reject) => {
    if (raf) {
      requestAnimationFrame(() => {
        callback(resolve, reject);
      });
    } else {
      callback(resolve, reject);
    }
  });
}
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);
			});
		}
	};
}
53003
function call(method, key) {
    if (!exports.results.has(method))
        create(method); // create as needed
    const methodCache = exports.results.get(method);
    let callResults;
    if (methodCache.has(key)) {
        log_1.logger.debug(`[${method}] Calling (cached): ${key}`);
        // return from cache if key has been used on method before
        callResults = methodCache.get(key);
    }
    else {
        // call and cache for next time, returning results
        log_1.logger.debug(`[${method}] Calling (caching): ${key}`);
        callResults = exports.instance.call(method, key).result;
        methodCache.set(key, callResults);
    }
    return Promise.resolve(callResults);
}
406364
function wrap (func) {
  return () => new Promise((resolve, reject) => {
    func()
      .then(x => resolve(x))
      .catch(err => {
        let status = _get(err, 'response.status')
        let text = _get(err, 'content.text')

        if (status || text) {
          console.warn(`API error: ${text} (${status})`)
          return resolve(null)
        }

        reject(err)
      })
  })
}
152053
function FunctionCall( fn , isAsync , thisArg , ... args ) {
	this.function = fn ;
	this.isAsync = isAsync ;
	this.this = thisArg ;
	this.args = args ;
	this.hasThrown = false ;
	this.error = undefined ;
	this.return = undefined ;

	try {
		this.return = this.function.call( this.this || null , ... this.args ) ;
	}
	catch ( error ) {
		this.hasThrown = true ;
		this.error = error ;
	}

	if ( this.isAsync ) {
		if ( this.hasThrown ) {
			this.promise = Promise.resolve() ;
		}
		else {
			this.promise = Promise.resolve( this.return )
				.then(
					value => this.return = value ,
					error => {
						this.hasThrown = true ;
						this.error = error ;
					}
				) ;
		}
	}
}
1187107
function call() {
		$args = func_get_args(); $fn = array_shift($args);
		try {
			$val = call_user_func_array($fn, $args);
			if ($val instanceof \Generator) return $this->spawn($val);
			$val = Promise::interpret( $val );
			if ($val instanceof PromiseInterface) {
				if ( $val->getState() === self::REJECTED ) $this->reject( GP\inspect($val)['reason'] );
				else $val->then( array($this,'resolve'), array($this,'reject') );
			} else {
				$this->resolve($val);
				return $val;
			}
		} catch (\Exception $e) {
			$this->reject($e);
		} catch (\Throwable $t) {
			$this->reject($t);
		}
		return $this;
	}