Wrap the default eval with a handler that resolves promises
766710
function wrapReplEval(replServer) {
  const defaultEval = replServer.eval;

  return function(code, context, file, cb) {
    return defaultEval.call(this, code, context, file, (err, result) => {
      if (!result || !result.then) {
        return cb(err, result);
      }

      result.then(resolved => {
        resolvePromises(result, resolved);
        cb(null, resolved);
      }).catch(err => {
        resolvePromises(result, err);

        console.log('\x1b[31m' + '[Promise Rejection]' + '\x1b[0m');
        if (err && err.message) {
          console.log('\x1b[31m' + err.message + '\x1b[0m');
        }

        // Application errors are not REPL errors
        cb(null, err);
      });
    });

    function resolvePromises(promise, resolved) {
      Object.keys(context).forEach(key => {
        // Replace any promise handles in the REPL context with the resolved promise
        if (context[key] === promise) {
          context[key] = resolved;
        }
      });
    }
  };
}
420637
function () {
  var handlers = {};

  function raise (ev) {
    if (handlers[ ev ]) {
      handlers[ ev ].apply(undefined, Array.prototype.slice.call(arguments, 1));
    }
  }

  function on (ev, handle) {
    handlers[ ev ] = handle;
  }

  function reset () {
    handlers = {};
    this.close = noOp;
    this.createChannel = noOp;
    this.createConfirmChannel = noOp;
    this.release = noOp;
  }

  var instance = {
    acquire: function () {
      this.raise('acquiring');
      return Promise.resolve();
    },
    item: { uri: '' },
    close: noOp,
    createChannel: noOp,
    createConfirmChannel: noOp,
    on: on,
    raise: raise,
    release: noOp,
    reset: reset
  };
  setTimeout(instance.acquire.bind(instance), 0);
  return instance;
}
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)
      })
  })
}
783105
function wrapOptions(method, model, options) {
  return function(err, res) {
    if (err) {
      if (options.error) {
        return options.error(res, err);
      }
      console.error('An error ocurred with no handler specified!', err);
      throw err;
    }

    if (options.success) {
      return options.success(res);
    } 
  };
}
772084
function eval(req, res, source, args) {
  this.spawn();
  this.reply(req, res, this._limit);
  // need to coerce buffers for the moment
  args = args.map(function(a) {
    if(a instanceof Buffer) return a.toString();
    return a;
  })
  this.ps.send({event: 'eval', source: source, args: args});
}
138068
function processTerm (handler, obj = {}, isDefault) {
  let req = {
    term: this._request.term.then(value => {
      assignRequest(req, this._request, obj)
      if (this._request.error && !isDefault) return null
      if (isDefault) req.error = null
      return handler(value, req)
    })
  }
  return new v(this._client, req)
}
586169
function init(resolver) {
			var handler = new Pending();

			try {
				resolver(promiseResolve, promiseReject, promiseNotify);
			} catch (e) {
				promiseReject(e);
			}

			return handler;

			/**
			 * Transition from pre-resolution state to post-resolution state, notifying
			 * all listeners of the ultimate fulfillment or rejection
			 * @param {*} x resolution value
			 */
			function promiseResolve (x) {
				handler.resolve(x);
			}
			/**
			 * Reject this promise with reason, which will be used verbatim
			 * @param {Error|*} reason rejection reason, strongly suggested
			 *   to be an Error type
			 */
			function promiseReject (reason) {
				handler.reject(reason);
			}

			/**
			 * @deprecated
			 * Issue a progress event, notifying all progress listeners
			 * @param {*} x progress event payload to pass to all listeners
			 */
			function promiseNotify (x) {
				handler.notify(x);
			}
		}
187214
function wrapHandler(handler) {
  return function (state) {
    for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
      args[_key - 1] = arguments[_key];
    }

    return _lodash2.default.assign({}, state, handler.apply(undefined, [state].concat(args)));
  };
}
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;
      };
    }
1051275
function runHandler(plugin, handler, cancel) {
  return function runHandlerDelegate(data) {
    if (!data) {
      return Promise.resolve();
    }

    return Promise
      .resolve(handler.handler(data, plugin, cancel))
      .then(function(result) {
        return data.configure(result);
      });
  };
}
568882
function wrap(err, js) {
		if (err) { return next(err); }

		var deps = exports.dependencies(id, js), params = [], undef = '';

		// make sure require, exports, and module are properly passed into the factory
		if (/\brequire\b/.test(js)) { params.push('require'); }
		if (/\bexports\b/.test(js)) { params.push('exports'); }
		if (/\bmodule\b/.test(js)) { params.push('module'); }

		// make sure code follows the `exports` path instead of `define` path once wrapped
		if (/\bdefine\.amd\b/.test(js)) { undef = 'var define;'; }

		if (deps.length) {
			deps = ',' + JSON.stringify(params.concat(deps));
		} else if (params.length) {
			params = [ 'require', 'exports', 'module' ];
		}

		js = 'define(' + JSON.stringify(id) + deps + ',function(' + params + ')' +
				'{' + js + '\n' + undef + '}' + // rely on hoisting for define
			');\n';
		next(null, js);
	}
560185
function execute(req, res) {
  ScriptManager.eval(req, res, '' + req.args[0], req.args.slice(1));
}
496041
function EvalRoute (ctx, next) {
	let router = this;
	let matched = router.match(router.opts.routerPath || ctx.routerPath || ctx.path, ctx.method);
	/* istanbul ignore else */
	if (ctx.matched) {
		ctx.matched.push.apply(ctx.matched, matched.path);
	} else {
		ctx.matched = matched.path;
	}
	if (matched.route) {
		return this.middleware()(ctx, next);
	} else {
		return Promise.resolve('koaton-no-route');
	}
}
693889
function execPromise (fn) {
  return new Promise(function (resolve) {
    resolve(fn(process.argv.slice(2)))
  }).then(onSuccess, onError)
}
182413
async function repeatablePromise (initialAssumptions, assumptionsFromResult, promiseGenerator) {
    let promise = promiseGenerator(initialAssumptions);
    let result = await promise;
    let finalAssumptions = assumptionsFromResult(result);
    if (JSON.stringify(initialAssumptions) === JSON.stringify(finalAssumptions)) {
        return promise;
    } else {
        return promiseGenerator(finalAssumptions);
    }
}
659955
function promisify(repl) {
  var _eval = repl.eval;
  repl.eval = function(cmd, context, filename, callback) {
    _eval.call(repl, cmd, context, filename, function(err, res) {
      if (isPromiseLike(res)) {
        res.then(function(ret) {
          callback(null, ret);
        }, function(err) {
          callback(err);
        });
      } else {
        callback(err, res);
      }
    });
  };
  return repl;
}
1327827
function(method) {
            return _.find(this.methods, function(handler) {
                return handler.regexp.test(method);
            }) || this.defaultHandler;
        }