Creates a Mongoose promise.
555786
function createMongoosePromise(resolver) {
    var promise

    // mongoose 5 and up
    if (parseInt(mongoose.version) >= 5) {
      promise = new mongoose.Promise(resolver)
    }
    // mongoose 4.1 and up
    else if (mongoose.Promise.ES6) {
      promise = new mongoose.Promise.ES6(resolver)
    }
    // backward compatibility
    else {
      promise = new mongoose.Promise
      resolver(promise.resolve.bind(promise, null), promise.reject.bind(promise))
    }

    return promise
  }
855426
function asPromise (val) {
	if (val && typeof val.then === 'function') {
		return val;
	}
	var deferred = new PromiseFactory();
	deferred.resolve(val);
	return deferred.promise();
}
1142602
function promiseMiddleware (request, response, middleware) {
  return new promiseMiddleware.Promise(function (resolve, reject) {
    middleware(request, response, function next (error) {
      return error ? reject(error) : resolve()
    })
  })
}
1336700
function mongooseInit(mongoose, logger, config) {
  const Log = logger.bind('mongoose-init')

  mongoose.Promise = Promise

  logUtil.logActionStart(
    Log,
    'Connecting to Database',
    _.omit(config.mongo, ['pass'])
  )

  mongoose.connect(config.mongo.URI)

  globals.mongoose = mongoose

  Log.log('mongoose connected')

  return mongoose
}
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);
        });
    }
255183
function create(req, res, next) {
  var body = req.body
    , slug = string.slugify(body.title);

  db.tags.findBySlug(slug, function(err, tag) {
    if(err && err.statusCode != 404) { return next(err); }

    if(tag) {
      res.json(201, tag);
    } else {
      db.tags.create(req.body, function(err, tag) {
        if(err) {
          next(err);
        } else {
          res.json(201, tag);
          signals.emit('tag:create', tag);
        }
      });
    }
  });
}
574127
function findById(schemaName, id) {
	return new Promise(function(resolve, reject) {
		var Model = db.mongoose.model(schemaName);

		Model
		.findById(id)
		.exec(function(error, result) {
			if (error) {
				reqlog.error('internal server error', error);
				reject(error);
			} else {
				resolve(result || 'notFound');
			}
		});
	});
}
1026911
function (requestPromise) {
  var that = this;

  // this will be bound to Client instance later in the Client constructor
  if (!this.isValid) {
    return Promise.reject(new Model({Errors: this.errors.join(',')}));
  }

  return requestPromise.apply(null, slice.call(arguments, 1))
    .then(function (response) {
      return new Model(response);
    }, function (reason) {
      var errors = that.errors;
      if (reason.statusCode >= 400 && reason.statusCode < 500) {
        errors.push(ClientError.HTTP_CLIENT_ERROR);
      } else if (reason.statusCode >= 500 && reason.statusCode < 600) {
        errors.push(ClientError.HTTP_SERVER_ERROR);
      } else {
        errors.push(ClientError.EXCEPTION);
      }
      return Promise.reject(new Model({Errors: errors.join(',')}));
    });
}
513291
function mongooseify(obj, returnValues) {

        applyMethods(obj);

        traverse(obj, (key, value) => {
            applyMethods(value);
        });

        function applyMethods(value) {
            if(value && value.hasOwnProperty('_id')) {
                value.toObject = jasmine.createSpy('toObject');
                value.toObject.and.returnValue(JSON.parse(JSON.stringify(value)));
                value.save = jasmine.createSpy('save');
                value.save.and.returnValue(returnValues && returnValues.save ? returnValues.save : Promise.resolve({name : 'fooy'}));
            }
        }
    }
510495
function makeDir(dir) {
    return new Promise(function ($return, $error) {
        var res;
        return Promise.resolve(makePromise(fs.mkdir, dir, dir)).then(function ($await_8) {
            try {
                res = $await_8;
                return $return(res);
            } catch ($boundEx) {
                return $error($boundEx);
            }
        }.bind(this), $error);
    }.bind(this));
}
431434
function formAsPromise (req, modelName, formDsl) {

    return new Promise((resolve, reject) => {

        form(req, modelName, (err, decoratedForm) => {

            if (err) {
                return reject(err);
            }

            return resolve(decoratedForm);

        }, formDsl);

    });

}
921149
function makeRequest (path, params) {
    // The api key will always be sent as a query parameter
    params = params || {}
    params.token = apiKey

    return new Promise(function (resolve, reject) {
      request(`${hostname}${path}?${querystring.stringify(params)}`,
        function (error, response, body) {
          if (error) {
            reject(error)
          }
          try {
            var result = JSON.parse(body)
            if (response.statusCode === 200) {
              resolve(result)
            }
            reject(result.error)
          } catch (error) {
            reject(response.statusMessage)
          }
        })
    })
  }
826078
function callPromise(fn, args) {
	return new Promise((resolve, reject) => {
		// promisified callback
		function callback(err,other) {
			// check if the 'err' is boolean, if so then this is a 'exists' callback special case
			if (err && (typeof err !== 'boolean')) return reject(err);
			// convert arguments to proper array, ignoring error argument
			let args = Array.prototype.slice.call(arguments, 1);
			// if arguments length is one or more resolve arguments as array,
			// otherwise resolve the argument as is.
			return resolve(args.length < 2 ? args[0] : args);
		}
		fn.apply(null, args.concat([callback]));
	});
}
156987
public function build(): AwaitPromiseRequest
	{
		$instance = new AwaitPromiseRequest();
		if ($this->promiseObjectId === null) {
			throw new BuilderException('Property [promiseObjectId] is required.');
		}
		$instance->promiseObjectId = $this->promiseObjectId;
		$instance->returnByValue = $this->returnByValue;
		$instance->generatePreview = $this->generatePreview;
		return $instance;
	}
47439
function createModel (app, name, options) {
  const mongooseClient = app.get('mongoose');
  assert(mongooseClient, 'mongoose client not set by app');
  const schema = new mongooseClient.Schema({ any: {} }, {strict: false});
  return mongooseClient.model(name, schema);
}
1212669
function makeRequest(url) {
    return new Promise(function (resolve, reject) {
      request.get(url).responseType('json').type('application/json').accept('application/json').end(function (err, res) {
        if (err) {
          reject(err);
        } else {
          resolve(res.body);
        }
      });
    });
  }
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);
    }
}