Sindbad~EG File Manager

Current Path : /home/infinitibizsol/.trash/node_modules.10/mongoose/lib/helpers/query/
Upload File :
Current File : /home/infinitibizsol/.trash/node_modules.10/mongoose/lib/helpers/query/wrapThunk.js

'use strict';

const MongooseError = require('../../error/mongooseError');

/**
 * A query thunk is the function responsible for sending the query to MongoDB,
 * like `Query#_findOne()` or `Query#_execUpdate()`. The `Query#exec()` function
 * calls a thunk. The term "thunk" here is the traditional Node.js definition:
 * a function that takes exactly 1 parameter, a callback.
 *
 * This function defines common behavior for all query thunks.
 * @param {Function} fn
 * @api private
 */

module.exports = function wrapThunk(fn) {
  return function _wrappedThunk(cb) {
    if (this._executionStack != null) {
      let str = this.toString();
      if (str.length > 60) {
        str = str.slice(0, 60) + '...';
      }
      const err = new MongooseError('Query was already executed: ' + str);
      err.originalStack = this._executionStack.stack;
      return cb(err);
    }
    this._executionStack = new Error();

    fn.call(this, cb);
  };
};

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists